I have a list view with items containing multiple buttons. The layout for one item looks something like this:
I have an overlaying transparent view, covering each entire list item. This view listens to two gestures: onDoubleTap
and onSingleTapConfimred
.
To trigger the click listeners on the underlying buttons i can just dispatch the touch events from the overlaying touch listener, but this does not show the selectors and states on the buttons (for example changed background color on press). I also only want the trigger click events when the overlaying view has fired onSingleTapConfimred
...
final DtGestureDetector detector = new DtGestureDetector(position);
final GestureDetector gd = new GestureDetector(convertView.getContext(), detector);
postViewHolder.viewOverlay.setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
//i want to trigger this only onSingleTapConfirmed and set the view selector on touch
//postViewHolder.txtMessage.onTouchEvent(event);
//postViewHolder.layPhoto.onTouchEvent(event);
gd.onTouchEvent(event);
return true;
}
});
...
private class DtGestureDetector extends GestureDetector.SimpleOnGestureListener {
private int position;
public DtGestureDetector(int position) {
super();
this.position = position;
}
public boolean onDoubleTap(MotionEvent e) {
Log.d(tag, "DoubleTap"+position);
return true;
}
@Override
public boolean onSingleTapConfirmed(MotionEvent e) {
Log.d(tag, "SingleTap"+position);
return true;
}
}
I could solve this by setting state programmatically
int[] state = new int[] {android.R.attr.state_window_focused, android.R.attr.state_focused};
drawable.setState(state);