Rafael Salvador
Rafael Salvador

Reputation: 58

Gridview does not fire OnLongClickListener

I have an empty gridview that fills a column in a tablelayout, I want to longpress that gridview and shou a quickaction popup.

The empty gridview does not fire longpress event.

gridTue.setOnLongClickListener(new OnLongClickListener() {

    @Override
    public boolean onLongClick(View v) {
        // TODO Auto-generated method stub
        return false; //I've breackpoint this line to test if it fires or not
    }
});

XML:

<GridView
            android:id="@+id/gridTue"
            android:numColumns="1"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:gravity="center"
            android:longClickable="true"
            android:background="@android:color/background_light" />

Upvotes: 0

Views: 1104

Answers (3)

Pavan
Pavan

Reputation: 1

setOnItemLongClickListener worked for me instead of setOnLongClickListener as said above post.

Upvotes: 0

android developer
android developer

Reputation: 116332

in case you wish to long click an item on the gridView, you should use setOnItemLongClickListener .

if you wish to be able to long click the gridView itself, your code seems ok. maybe you've added some views inside it that catch the event? if so, you could use setOnTouchListener, or put the gridView in a layout that will catch this event.

Upvotes: 4

Eliel Haouzi
Eliel Haouzi

Reputation: 607

maybe your gridView is in a ListView and then the events has handles by the listview and not by the gridview.

Upvotes: 0

Related Questions