I have an ImageButton when i press it and keep my finger down it becomes invisible, when i lift my finger it becomes visible again.
But when i press the button and while my finger is down i move it away from it and lift it up it doesn’t become visible again
The code looks like this
final ImageButton b=(ImageButton)findViewById(R.id.timer_btn);
b.setOnTouchListener(new View.OnTouchListener() {
public boolean onTouch(View v, MotionEvent event) {
switch (event.getAction()) {
case MotionEvent.ACTION_UP:
b.setVisibility(View.VISIBLE);
Log.w("app", "Action up");
return true;
case MotionEvent.ACTION_DOWN:
b.setVisibility(View.INVISIBLE);
Log.w("app", "Action down");
}
return false;
}
});
I tried using
case MotionEvent.ACTION_OUTSIDE:
b.setVisibility(View.VISIBLE);
Log.w("app", "Action outside");
}
but it doesn’t work, it gets called no matter if it’s outside the button or inside
you have to use the
ACTION_CANCEL.I guess the ACTION_OUSIDE is for outside the actual screen.
The system will always calls either the UP or the CANCEL.
edit:
I believe this should work: