Tony
Tony

Reputation: 1603

How to prevent OnItemClickListener work when long click performed?

I have a gridview and i want its items to act different if user performs click or long click that is why i am using OnItemClickListener and OnItemLongClickListener but when long click happens both listeners react.I want to perform only OnItemLongClickListener.

Upvotes: 13

Views: 7471

Answers (3)

meizilp
meizilp

Reputation: 3921

public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {   
   return true;
}

return true will be prevent click event to be continue. It will be perform only OnItemLongClickListener.

Upvotes: 48

Barmaley
Barmaley

Reputation: 16363

In order to intercept long cliks (aka tapping) you should imlement GestureDetector.OnGestureListener

Upvotes: -1

Tony
Tony

Reputation: 1576

You can use AdapterView.setOnItemLongClickListener. GridView inherits AdapterView, so you can invoke that method on GridView too.

Upvotes: 0

Related Questions