I'm trying to code an imageView click feedback using the onTouch method. My code is used to scale the imageView when pressed(MotionEvet.ACTION_DOWN
) and return to its normal size when the user stop pressing(MotionEvet.ACTION_UP
). But what I'm not able to code is the action when the user drags its finger out of the imageView.
I've seen a solution which tells to use MotionEvent.ACTION_CANCEL
at the beginning of the switch statement, but this doesn't work for me.
My code is the next one:
public boolean onTouch(View v, MotionEvent event) {
int action = event.getAction();
switch (action) {
case MotionEvent.ACTION_CANCEL:
clickOutTransformation(ico);
return true;
case MotionEvent.ACTION_UP:
clickOutTransformation(ico);
switch (i) {
case 1:
fondoApp.setBackgroundResource(R.drawable.back_blue_bubbles_lite);
i++;
break;
case 2:
fondoApp.setBackgroundResource(R.drawable.back_espectrum);
i++;
break;
case 3:
fondoApp.setBackgroundResource(R.drawable.back_black_and_violet);
i++;
break;
case 4:
fondoApp.setBackgroundResource(R.drawable.back_green);
i++;
break;
case 5:
fondoApp.setBackgroundResource(R.drawable.back_blur_blue_ed);
i = 1;
break;
default:
break;
}
return true;
case MotionEvent.ACTION_DOWN:
clickInTransformation(ico);
return true;
default:
break;
}
return false;
}