Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

onClickListener triggers after onLongClickListener

I have one View for which both onClickListener and onLongClickListener implemented. When I long click the view onClickListener triggers also, I don't need it to be executed when I do long click. Any ways to prevent it from being executed at time of long click?

like image 826
Eugene Avatar asked Sep 14 '11 20:09

Eugene


2 Answers

return true; from the long click callback to signal that you've handled the event

like image 57
Rich Avatar answered Nov 19 '22 00:11

Rich


Return true instead of false from onItemLongClick.

Reason: Return true if the callback consumed the long click, false otherwise.

Example:

listView.setOnItemLongClickListener(new OnItemLongClickListener() {

    @Override
    public boolean onItemLongClick(AdapterView<?> adapterView, View view,
            int position, long id) {
        // TODO Auto-generated method stub
        /******
        Change Here true instead of false.
        *******/
        return true;
    }
});
like image 34
Pratik Butani Avatar answered Nov 18 '22 22:11

Pratik Butani