When taping on an ImageView
, I want to replace it with other drawable depending on the previous drawable, with some researches I made this:
ImageView imgview = (ImageView) findViewById(R.id.imageView1);
imgview.setOnClickListener(new OnClickListener() {
public void onClick(View view) {
ImageView imageView = (ImageView) view;
assert(R.id.imageView1 == imageView.getId());
Integer integer = (Integer) imageView.getTag();
integer = integer == null ? 0 : integer;
switch (integer) {
case R.drawable.number1:
imageView.setImageResource(R.drawable.number2);
imageView.setTag(R.drawable.number2);
break;
case R.drawable.number2:
imageView.setImageResource(R.drawable.number3);
imageView.setTag(R.drawable.number3);
break;
case R.drawable.number3:
imageView.setImageResource(R.drawable.number4);
imageView.setTag(R.drawable.number4);
break;
default:
Toast.makeText(MainActivity.this, "exceeded", Toast.LENGTH_SHORT).show();
}
}
});
}
The problem is the app always calls to the toast
message in default
. It ingores all other treatments/verifications in case
sections.
Any idea please to solve that problem?
Thank you very much.