当我单击列表视图项目时,它调用onitemclick侦听器,但是当我单击项目时,它同时调用initemclick和onitemlongclick侦听器。长按时如何解决仅调用onitemlongclick监听器的问题?
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
}
}
最佳答案
注意,onItemLongClick()具有布尔返回值。如果您不希望调用onItemClick,请使onItemLongClick()返回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;
}
}
关于android - Android ListView onitemclick监听器,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/13620342/