My requirement is, on single click on Edit Text, user can enter data, on double click go to an activity where all data will be present.
I used the logic for press again to exit, I am unable to achieve it.
ETBarCode.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
doublePress=doubleTap();
if(doublePress) {
ETBarCode.requestFocus();
InputMethodManager imm=(InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(ETBarCode.getWindowToken(), 0);
}
else
{
Toast.makeText(MoveActivity.this, "Enter Data", Toast.LENGTH_SHORT).show();
ETBarCode.requestFocus();
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.showSoftInput(ETBarCode, 0);
}
}
});
}
private boolean doubleTap()
{
if (doubleBackToExitPressedOnce) {
Toast.makeText(this, "Scanning", Toast.LENGTH_SHORT).show();
return doubleBackToExitPressedOnce;
}
this.doubleBackToExitPressedOnce = true;
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
doubleBackToExitPressedOnce = false;
}
}, 2000);
return doubleBackToExitPressedOnce;
}
Is there any way to sort it out?
You can manage with counter variable:
Hope this will help you.
This should solve your problem. I tried changing as little as possible from your code, however some things are not clear (where exactly are you redirecting to the new activity?). Also, I would not recommend this double tap to proceed thing in terms of user experience, it is very unconventional. I would rather have it as clickable TextView (with design clearly suggesting the clickability) for the "view" action, and an image button (the good old android pencil) next to it for the "edit" action.
Use
GestureDetector
to detect: