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!
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With