点击Android图库中的图片后,我需要将其更改为其他图片。
我正在使用Imageadapter在图库中设置一个图像数组,使用onItemClickListener,现在,它可以提供消息 - 我需要onItemClick将图库中的图像更改为Imageadapter之外的另一个图像阵列。
以下是图库代码:
Gallery ga = (Gallery)findViewById(R.id.Gallery01);
ga.setAdapter(new ImageAdapter(this));
imageView = (ImageView)findViewById(R.id.ImageView01);
ga.setOnItemClickListener(new OnItemClickListener() {
//@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
long arg3) {
Toast.makeText(getBaseContext(),
"You have selected icon " + (arg2+1) + " in Lifestyles",
Toast.LENGTH_SHORT).show();
}
});
这是ImageAdapter:
public class ImageAdapter extends BaseAdapter {
private Context ctx;
int imageBackground;
public ImageAdapter(Context c) {
ctx = c;
}
//@Override
public int getCount() {
return pics.length;
}
//@Override
public Object getItem(int arg1) {
return arg1;
}
//@Override
public long getItemId(int arg0) {
return arg0;
}
//@Override
public View getView(int arg0, View arg1, ViewGroup arg2) {
ImageView iv = new ImageView(ctx);
iv.setImageResource(pics[arg0]);
iv.setScaleType(ImageView.ScaleType.FIT_CENTER);
iv.setLayoutParams(new Gallery.LayoutParams(135,135));
iv.setBackgroundResource(imageBackground);
return iv;
}
private Integer[] pics = {
R.drawable.icon_0,
R.drawable.icon_1,
R.drawable.icon_2,
R.drawable.icon_3,
};
}
答案 0 :(得分:0)
我想在getView本身工作会更好,让onItemClick中的视图无效,然后在getView中更改图像