Let's say we have objects A, B. Initially object B has visibility set to GONE
and object A has visibility set to VISIBLE
.
Touching object A must make A GONE
and B VISIBLE
. Releasing B must make B GONE
and A VISIBLE
. Problem is that it must be done without pressing B again.
Set on touch event ACTION_DOWN
on A and ACTION_UP
on same A, that appears and hides B just like described. This cannot work, because ACTION_UP
is not triggered after setting visibility of A to GONE
.
Set on touch event ACTION_DOWN
on A that will make A GONE
and make B VISIBLE
, at same time new event listener is set such that ACTION_UP
on B would inverse visibility of the objects. This doesn't work either since after B appears, I need to release, press B again and then release to make it work.
Is it possible to to set onTouch listener in such way that object is assumed to be touched? So that there would be no need to press it again?
Is it possible to detect onTouch ACTION_UP
event after visibility of object is set to GONE
?
All ideas, examples, links will be appreciated. Thanks for help!
Try this
buttonA.setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
if(event.getAction() == MotionEvent.ACTION_DOWN) {
YourMethodForButtonBGoesVisible();
YourMethodForButtonAGoesGone();
} else if (event.getAction() == MotionEvent.ACTION_UP) {
YourMethodForButtonAGoesVisible();
YourMethodForButtonBGoesGone();
}
return true;
}
});
I don't know if when the button A gone this will detect the MotionEvent.ACTION_UP.