gpt4 book ai didi

安卓图库小部件 : triggering method on image change

转载 作者:行者123 更新时间:2023-11-29 18:15:55 24 4
gpt4 key购买 nike

public class GalleryImageAdapter extends BaseAdapter{

private Activity activity;
private ArrayList<String> listOfImages;
public ImageLoader imageLoader;


public GalleryImageAdapter(Activity a, ArrayList<String> listOfImages){
activity = a;
this.listOfImages = listOfImages;
imageLoader=new ImageLoader(activity.getApplicationContext());
}

@Override
public int getCount() {
return listOfImages.size();
}

@Override
public Object getItem(int position) {
return listOfImages.get(position);
}

@Override
public long getItemId(int position) {
return position;
}

@Override
public View getView(int position, View convertView, ViewGroup viewGroup) {
View v = convertView;


if (v == null) {
LayoutInflater vi = (LayoutInflater) activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
v = vi.inflate(R.layout.gallery_layout, null);

}



final String url = listOfImages.get(position);


ImageView galleryImage = (ImageView) v.findViewById(R.id.galleryImage);
imageLoader.DisplayImage(url, activity, galleryImage);


v.setLayoutParams(new Gallery.LayoutParams(LayoutParams.FILL_PARENT,200));
return v;
}


public float getScale(boolean focused, int offset) {
/* Formula: 1 / (2 ^ offset) */
return Math.max(0, 1.0f / (float)Math.pow(2, Math.abs(offset)));
}

}

我这里有我的图库适配器。我想知道是否有一种方法可以让我检测图像何时更改,并检索图像的位置编号,以便将其发送到我的 Activity 。

最佳答案

位置就是您所追求的。参见 AdapterView.OnItemSelectedListener .

    mGallery.setOnItemSelectedListener(new OnItemSelectedListener() {

@Override
public void onItemSelected(AdapterView<?> parent, View v,
int position, long id) {
// position will display it's place in the adapter
}

@Override
public void onNothingSelected(AdapterView<?> arg0) {
// Do nothing
}
});

关于安卓图库小部件 : triggering method on image change,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8095991/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com