I have been searching online and on StackOverflow for how to do an action in an onTouchListener if the event was a tap, not a motion of any kind, but I haven't been able to find an answer and what I have tried doesn't work either. I have a ListView Adapter and in the getView method, I have set the onTouchListener on the listItem.
What I want to do is when the listItem is tapped, I want to display a Toast, but if the event was a drag (like the user scrolling through the list), I don't want to display the Toast.
Below is the code that I have tried. (makeToast is a function for making a Toast and events.getRelation() is the String I want to have in the Toast.):
listItem.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_HOVER_ENTER) {
makeToast(events.getRelation());
} else if (event.getAction() == MotionEvent.ACTION_UP) {
// makeToast(events.getRelation());
} else if (event.getAction() == MotionEvent.ACTION_SCROLL) {
// makeToast(events.getRelation());
} else if (event.getAction() == MotionEvent.ACTION_MOVE) {
// makeToast(events.getRelation());
} else if (event.getAction() == MotionEvent.AXIS_SCROLL) {
// makeToast(events.getRelation());
} else if (event.getAction() == MotionEvent.AXIS_VSCROLL) {
// makeToast(events.getRelation());
} else {
//makeToast(events.getRelation());
}
return false;
}
});
I have tried having the makeToast method under different types of MotionEvents, but I still don't get the results I want because either a Toast is not made at all, or it is made when I am scrolling, not tapping. Would anyone be able to help me with this? I feel like it is a simple problem, but I have been unable to find a solution