I want to ask how to switch and select only one event under the listview. My code below is working. But when the OnItemLongClick fires, the OnItemClick also fires. How can I switch the event where only one event will be detected:
lstResult.setOnItemClickListener(new OnItemClickListener()
{
@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int position,
long arg3) {
// TODO Auto-generated method stub
//showToast(arg0.getItemIdAtPosition(position) + "");
String str = searchWhere(lstResult.getItemAtPosition(position) + "");
String word = lstResult.getItemAtPosition(position).toString();
showDialog(word,str);
}
});
lstResult.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
@Override
public boolean onItemLongClick(AdapterView<?> arg0, View arg1, int position, long arg3) {
// TODO Auto-generated method stub
showToast(lstResult.getItemAtPosition(position) + "");
return false;
}
});
According to documentation of OnItemLongClickListener:
Returns true if the callback consumed the long click, false otherwise
You should return true
if long click is fired.
Return boolean true at the end of OnItemLongClick.
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