I basically want to detect a long touch to my frameLayout, once detected I'll call an alert message that I have in a method.
frameLayout.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_DOWN)
{
first_tap = System.currentTimeMillis();
clicked = clicked + 1;
if (clicked == 2)
{
Toast.makeText(toolandmode.this, "Clicks:" + clicked, Toast.LENGTH_SHORT).show();
startTimer();
}
// else if (flag == 1)
// {
// Toast.makeText(toolandmode.this, "Clicks:" + clicked, Toast.LENGTH_SHORT).show();
// AlertMessage();
// flag = 0;
// }
}
return true;
}
});
My activity contains a timer which I start by double tapping the screen but rather than making another double tap as the trigger for my Alert message I want to simply touch the screen for long then the Alert Dialog I made would be triggered. So how do I do that?
I would suggest that you replace your current OnTouchListener code with a GestureDetector and a SimpleOnGestureListener. It supports both double tap and long press out of the box.
All you have to do is something like this:
For more details on how to add a GestureDetector to a view you can look at this post.