d
is not an id
. I'd suggest you to do like this:
// same listener for everyone
Imagepassone.setOnClickListener(imgButtonHandler);
Imagepasstwo.setOnClickListener(imgButtonHandler);
Imagepassthree.setOnClickListener(imgButtonHandler);
//...
// switch id for each view inside the same listener
View.OnClickListener imgButtonHandler = new View.OnClickListener() {
public void onClick(View v) {
// check the view clicked by id
if(v.getId() == R.id.Imagepassone) {
// do something like change background
if(image.getBackground() != getResources().getDrawable(R.drawable.passselect)) {
image.setBackgroundResource(R.drawable.passselect);
} else if((image.getBackground() == getResources().getDrawable(R.drawable.passselect)) &&
(image2.getBackground() != getResources().getDrawable(R.drawable.passselect)) {
image.setBackgroundResource(R.drawable.passselect);
}
} else if(v.getId() == R.id.Imagepasstwo) {
// do something
} else if(v.getId() == R.id.Imagepassthree) {
// do something
}
}
};
But I think this is not a proper way..
As I can see and understand, your image (image, image2, image3) are the top rounded image, right? If yes, you can try, by every click to change the step of these icons above and change their backgrounds. It will be better I think to do this with a local int
and change the step. Something like this should work:
// local variable just below ImageView image3; line
private int nbStep = 0;
// ...
Imagepassone.setOnClickListener(imgButtonHandler);
Imagepasstwo.setOnClickListener(imgButtonHandler);
Imagepassthree.setOnClickListener(imgButtonHandler);
// listener
View.OnClickListener imgButtonHandler = new View.OnClickListener() {
public void onClick(View v) {
// check id like above
if(v.getId() == R.id.Imagepassone) {
// augment the local int
nbStep++;
// call a general method to check the background with int
changeStepBackground(nbStep);
}
}
});
public void changeStepBackground(int i) {
// four step switch
switch(i) {
case 1:
image.setBackgroundResource(R.drawable.passselect);
break;
case 2:
image2.setBackgroundResource(R.drawable.passselect);
break;
case 3:
image3.setBackgroundResource(R.drawable.passselect);
break;
case 4:
image4.setBackgroundResource(R.drawable.passselect);
break;
}
}
I hope I understand clearly and this helps.