-1

I have a scenario in which I have to to add text and multiple images, something like below

"fooo bar enter image description here lorem ipsum enter image description here somtext.

and all these images have clicklisteners so I can know which image is being clicked.

Till now I am able to place images but unable to implement click listeners on that

ingsaurabh
  • 15,249
  • 7
  • 52
  • 81

1 Answers1

1

Associate a Tag with each imageview and Set a common onclick Listner for both imageview in onclick even find the imageview by tag associated with View in onClick() method Like

Let two imageview are iv1 and iv2

     iv1.setTag("TAG1");
     iv2.setTag("TAG2');

            OnClickListener oc=new OnClickListener() {

            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub

                      String tag=(String) v.getTag();
                            if(tag.equals("TAG1"))
                         {
                                  // Imageview is iv1                                  

                               }else{
                             // Imageview is iv2                                  
                                    }
            }
        };

Try it and let me know if problem exist

Jitendra Prajapati
  • 1,002
  • 1
  • 10
  • 33