我有一个功能代码,但在上次更新sdk后,我收到以下警告:
此行有多个标记
-当检测到点击时,Ontouch应该调用View PerformClick
-实现android.view.view.ontouchListener.ontouch

med.setOnTouchListener(new OnTouchListener() {
    public boolean onTouch(View v, MotionEvent event) {
        if (event.getAction() == MotionEvent.ACTION_DOWN) {
            detect.setEnabled(false);
        }
        if (event.getAction() == MotionEvent.ACTION_UP || event.getAction() == MotionEvent.ACTION_CANCEL) {
            detect.setEnabled(true);
        }
        //v.performClick();
        Log.e("next", "touch");
        return false;
    }
});

med.setOnClickListener(new OnClickListener() {
    public void onClick(View v) {
        if(!center) {
            send("1");
        } else {
            send("2");
        }
        Vibrate(100);
        Log.e("next","click");
    }
});

我的代码工作正常,但如果我取消v.performclick();以删除警告,则会出现不需要的行为。为什么我会收到这个警告,如果我放弃它,让代码保持原样,会有问题吗?
编辑:
这是我单击按钮时的日志:
“下一个”,“触摸”
“下一个”,“触摸”
“下一步”,“单击”
这是v.performclick()
“下一步”,“单击”
“下一个”,“触摸”
“下一步”,“单击”
“下一个”,“触摸”
“下一步”,“单击”

最佳答案

你应该把

v.performClick();

在第二个if中:
if (event.getAction() == MotionEvent.ACTION_UP ....) {
    v.performClick();
    detect.setEnabled(false);
}

07-28 02:20
查看更多