I have a single button named as CheckIn.Have a look at my code.
checkIn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(HomeSafeActivity.this, "Normal Press", Toast.LENGTH_LONG).show();
});
checkIn.setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
Toast.makeText(HomeSafeActivity.this, "Long press", Toast.LENGTH_LONG).show();
return false;
}
});
Now when i normal press the button the message shows as Normal press.When i Long press the button the message shows as long press as well as Normal press both. What i want that when i long press the button only long press event should triggered not the normal press event.How can i achieve this??
I got the solution of my Question.Return the true instead of false.Just see below:-
checkIn.setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
Toast.makeText(HomeSafeActivity.this, "Long preess", Toast.LENGTH_LONG).show();
return true;
}
});
onLongClick()
- This returns a boolean to indicate whether you have consumed the event and it should not be carried further. That is, return true
to indicate that you have handled the event and it should stop here; return false
if you have not handled it and/or the event should continue to any other on-click listeners
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With