I have 4 images. We should be able to click on these images.
I\'d like to know if I have to create 4 OnClickListener
, or there is another way to do this properly?>
You can use/make your listener this way:-
img1.setOnClickListener(imgClk);
img2.setOnClickListener(imgClk);
img3.setOnClickListener(imgClk);
img4.setOnClickListener(imgClk);
And then you have to create OnClickListener after onCreate/out side of onCreate()
public OnClickListener imgClk = new OnClickListener()
{
@Override
public void onClick(View v)
{
switch(v.getId()){
case R.id.img1:
//write your code here
break;
case R.id.img2:
//write your code here
break;
case R.id.img3:
//write your code here
break;
case R.id.img4:
//write your code here
break;
}
};
I hope it helps you.