Reputation: 1507
when i click my list view item it calls onitemclick listener but when i click item long it calls both initemclick and onitemlongclick listeners. how to solve only call onitemlongclick listener when it long press?
list.setOnItemClickListener(new OnItemClickListener()
{
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
long arg3) {
//my code
}
});
list.setOnItemLongClickListener(new OnItemLongClickListener() {
public boolean onItemLongClick(AdapterView<?> arg0, View arg1,int arg2, long arg3) {
//my code
}
}
Upvotes: 1
Views: 2708
Reputation: 1222
Try using return like this...
list.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
long arg3) {
}
});
list.setOnItemLongClickListener(new OnItemLongClickListener() {
public boolean onItemLongClick(AdapterView<?> arg0, View arg1,int arg2, long arg3) {
return true;
}
}
Upvotes: 0
Reputation: 24453
You just need to return false to tell system that it shouldn't deliver the event any more.
list.setOnItemLongClickListener(new OnItemLongClickListener() {
public boolean onItemLongClick(AdapterView<?> arg0, View arg1,int arg2, long arg3) {
//Do something
return false;
}
Upvotes: 0
Reputation: 9939
Notice that, onItemLongClick() has a boolean return value. If you don't want onItemClick to be called, make onItemLongClick() to return true.
list.setOnItemLongClickListener(new OnItemLongClickListener() {
public boolean onItemLongClick(AdapterView<?> arg0, View arg1,int arg2, long arg3) {
//....
// Above are your code.
// Return true for this method as below.
return true;
}
}
Upvotes: 2
Reputation: 448
In Such case better to use onClickListener() for individual views of the List instead of the list. And also for onItemLongClickListener() for the Views.
Upvotes: 0