Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Items in ListView not long clickable after setting click listener in getView()

I've searched around and have not come out with a solution (maybe not using the correct keywords).

So, I've a custom ListView which its item can be dragged around when the item is long clicked. Within its item, there's an ImageView and LinearLayout containing two TextViews. Actions are done when the LinearLayout or ImageView is clicked.

To do this, I've use setOnItemLongClickListener on my DragListView which extends ListView, to initiate drag action, and onInterceptTouchEvent to manage the drag action.

Then, I have built a custom adapter extending BaseAdapter and overrided its getView() to implement the child items in the row. The LinearLayout and ImageView have been setOnClickListener.

The problem is, the LinearLayout and ImageView are able to do their stuff, but the onItemLongClick isn't called.

The listener inside getView();

    holder.delete.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
//Do something
}

For item long click (drag initiator)

setOnItemLongClickListener(new OnItemLongClickListener() {              

    @Override
                public boolean onItemLongClick(AdapterView<?> parent, View view,
                        int position, long id) {
    //Do something
    }

Thank you very much!

like image 459
Yaobin Then Avatar asked Nov 04 '22 22:11

Yaobin Then


1 Answers

I think that a gesture detector is one of ways to handle events. Usually, however, a gesture detector is used when we want to detect a gesture not a long-press.

The reason why onItemLongClick isn't called is that onClickListener might consume a touch event. In that reason, if you want to handle onItemLongClick, intercept touch event and dispatch it to views you want to handle.

You can find more details following link. http://developer.android.com/guide/topics/ui/ui-events.html

like image 73
theWook Avatar answered Nov 15 '22 13:11

theWook