I've created a custom view on which you can draw a path with your finger. It extends View class.
When I use it inside a ListView as one of its items if a user touches custom view the ListView is scrolled. How can I prevent this from happening?
I suppose I need to get focus somehow on my custom view. But I don't know how.
Update:
I found possible solution. In my custom view's onTouchEvent(Motion event)
method I've placed getParent().requestDisallowInterceptTouchEvent(true);
.
Without this the event queue when user touches custom view looked like this:
When I receive MotionEvent
with code MotionEvent.ACTION_CANCEL
the ListView
starts to scroll.
Setting requestDisallowInterceptTouchEvent(true)
within child's onTouch(View, MotionEvent)
method works:
@Override
public View getView(int position, View convertView, ViewGroup parent) {
ViewGroup item = (ViewGroup) inflater.inflate(R.layout.list_item, null);
Button button = (Button)item.findViewById(R.id.list_item_btn);
button.setText("button " + position);
button.setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
listView.requestDisallowInterceptTouchEvent(true);
return false;
}
});
return item;
}
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