Skip to content Skip to sidebar Skip to footer

How To Identified Which Image Is Clicked In Imageview

ImageView imageAd =(ImageView) findViewById(R.id.HomeimageViewAd); ad4 and ad5 are changing on regular interval in imageAd (i.e imageview) and i want to find which image is click

Solution 1:

Set id to imageviews like this imageView.setId(imageArray[i]);

Then check with id. The entire code will be like as follows

Bitmap bmp= BitmapFactory.decodeResource(getResources(),imageArray[i]);
        imageAd.setImageBitmap(bmp);
        imageAd.setId(imageArray[i]);
        imageAd.setOnClickListener(newOnClickListener() {
         @OverridepublicvoidonClick(View v) {
             if(v.getId()==R.drawable.ad4){

                 } 
        } } );

Post a Comment for "How To Identified Which Image Is Clicked In Imageview"