8

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?

Eugene
  • 59,186
  • 91
  • 226
  • 333

2 Answers2

25

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

Pratik Butani
  • 60,504
  • 58
  • 273
  • 437
Rich
  • 36,270
  • 31
  • 115
  • 154
  • @Rich I tried your solution for a similar issue with no luck. I'd appreciate any insights or thoughts, located here: https://stackoverflow.com/questions/47783631/recyclerview-how-to-add-onclick-and-keep-onlongclick-working – AJW Dec 16 '17 at 03:22
1

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;
    }
});
Pratik Butani
  • 60,504
  • 58
  • 273
  • 437
  • @Pratk Butani I tried your solution but it did not resolve my issue. I'd appreciate any insights or thoughts you can provide, located here: https://stackoverflow.com/questions/47783631/recyclerview-how-to-add-onclick-and-keep-onlongclick-working – AJW Dec 16 '17 at 03:24