2

我有一个包含多个按钮的项目的列表视图。一项的布局如下所示:

黑框代表一个列表视图项

我有一个覆盖的透明视图,覆盖了整个列表项。此视图监听两个手势:onDoubleTaponSingleTapConfimred

要触发底层按钮上的点击侦听器,我可以从覆盖的触摸侦听器中分派触摸事件,但这不会显示按钮上的选择器和状态(例如,按下时更改了背景颜色)。我也只想要在覆盖视图触发时触发点击事件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;
    }
}
4

1 回答 1

0

我可以通过以编程方式设置状态来解决这个问题

int[] state = new int[] {android.R.attr.state_window_focused, android.R.attr.state_focused};
drawable.setState(state);
于 2018-01-05T09:30:42.337 回答