Android: Why does long click also trigger a normal click?
From Event Listeners:
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.
Are you returning true
from your onLongClick()
and still getting the normal click event?
Edited to add: For a ListView, you may be using OnItemLongClickListener
. The onItemLongClick()
there uses a similar boolean return value to indicate whether it consumed the event.
Perform both the normal click and long click at button
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;
}
});
Why does onClick does not fire drag listener, but on Long click works fine?[android]
For a click event to occur, you must lift your finger (ACTION_UP
), which wouldn't make sense with starting a drag action. A long click, on the other hand, happens with your finger still on the screen. (A more appropriate name might have been "long press".)
If you want to start a drag right when your finger first touches the View, you can do so with an OnTouchListener
, when the ACTION_DOWN
event happens.
How to prevent OnItemClickListener work when long click performed?
public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
return true;
}
return true will be prevent click event to be continue. It will be perform only OnItemLongClickListener
.
android 4.4.2 onListItemClick() and onItemLongClick() fired on long click
In the onLongClick
method of your onLongClickListener, return true to indicate that you have consumed the click event.
public boolean onLongClick(View v) {
// DO STUFF
return true;
}
If you return false, you indicate that you haven't handled the event and/or want it to trigger any other on-click listeners.
How do I add proper longclick and normal click at the same time to my button?
Well you should implement your own code but here are the basics
btnList.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View vi) {
}
});
btnList.setOnLongClickListener(new OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
return false;
}
});
recycleview onLongclick automatically calls onClick
Returning true will tell the system i have handle the event you dont have to worry chill yourself otherwise Onclick
will fire.
@Override
public boolean onLongClick(View v) {
onclicklistner.onItemLongClick(getAdapterPosition(), v);
return true;
}
Related Topics
How to Load Image as Bitmap to Glide
Stop Scrollview from Auto-Scrolling to an Edittext
How to Remove White Underline in a Searchview Widget in Toolbar Android
How to Capture Key Events from Bluetooth Headset with Android
Android Gcm Sender_Id, How to Get It
How to Import Eclipse Library Project from Github to Android Studio Project
How to Run a Specific Android App Using Terminal
How to Get a List of Android Permissions
Adb Doesn't Recognize My Galaxy Nexus - Win7
Getting Gradle Error "Could Not Reserve Enough Space for Object Heap" Constantly in Intellij Idea
Get Application Installed Date on Android
Detecting The Scrolling Direction in The Adapter (Up/Down)
No Repository Found Error in Installing Adt in Eclipse Indigo
Action Bar Back Button Not Working
Export The Contacts as Vcf File