ImageView imageAd =(ImageView) findViewById(R.id.HomeimageViewAd);
ad4和ad5在imageAd(即imageview)中定期更改,我想查找哪个图片是
//数组中的图像资源
private int[] imageArray = {
R.drawable.ad4,
R.drawable.ad5
};
Bitmap bmp= BitmapFactory.decodeResource(getResources(),imageArray[i]);
imageAd.setImageBitmap(bmp);
imageAd.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// here i want to identified which image is clicked
} } );
答案 0 :(得分:0)
将ID设置为像这样的imageviews imageView.setId(imageArray [I]);
然后用id检查。 整个代码如下所示
Bitmap bmp= BitmapFactory.decodeResource(getResources(),imageArray[i]);
imageAd.setImageBitmap(bmp);
imageAd.setId(imageArray[i]);
imageAd.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
if(v.getId()==R.drawable.ad4){
}
} } );