如何在onTouch方法中获取GesturDetector.onSingleTapConfirmed()返回值?

时间:2018-04-25 04:38:17

标签: android ontouchlistener gesturedetector

我有以下代码,只需在按钮上设置onTouchListener GestureDetector

public class MainActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    Button btn = findViewById(R.id.btn);

    final GestureDetector gd = new GestureDetector(this, new GestureDetector.SimpleOnGestureListener() {
        @Override
        public boolean onSingleTapConfirmed(MotionEvent e) {
            return true;
        }
    });

    btn.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            boolean res = gd.onTouchEvent(event);
            Log.i("res", "res = " + res);
            return res;
        }
    });
}

}

但是,日志显示res值始终为false且永远不为true,这意味着我的onSingleTapConfirmed回调永远不会将其返回值传递回onTouch()方法。有什么方法可以在onSingleTapConfirmed方法中获得onTouch的返回值吗?

0 个答案:

没有答案