onTouchListener警告:onTouch应该调用查看#performClick点击被检测到时onTouchListener、onTouch、performClick

2023-09-04 06:11:38 作者:偷亲一口月亮

我创建了一个 onTouchListener 。不幸的是onTouch()方法抛出我一个警告:

  COM /计算器/ activitys /计算器$ 1号onTouch应该调用查看#performClick点击时检测
 

这是什么意思?我还没有发现有关此警告的任何信息。这里是全code:

 的LinearLayout llCalculatorContent =(的LinearLayout)fragmentView.findViewById(R.id.calculator_content);

llCalculatorContent.setOnTouchListener(新View.OnTouchListener(){

    @覆盖
    公共布尔onTouch(视图V,MotionEvent事件){
        Tools.hideKeyboard(getActivity(),getView());
        。getView()clearFocus();
        返回false;
    }
});
 

解决方案

在这里你去:

 公共布尔onTouch(视图V,MotionEvent事件){
    开关(event.getAction()){
    案例MotionEvent.ACTION_DOWN:
        //一些code ....
        打破;
    案例MotionEvent.ACTION_UP:
        v.performClick();
        打破;
    默认:
        打破;
    }
    返回true;
}
 
View的事件分发

I have created a onTouchListener. Unfortunately onTouch() method throws me a warning:

com/calculator/activitys/Calculator$1#onTouch should call View#performClick when a click is detected

What does it means? I have not found any information about this warn. Here is the full code:

LinearLayout llCalculatorContent = (LinearLayout) fragmentView.findViewById(R.id.calculator_content);

llCalculatorContent.setOnTouchListener(new View.OnTouchListener() {

    @Override
    public boolean onTouch(View v, MotionEvent event) {
        Tools.hideKeyboard(getActivity(), getView());
        getView().clearFocus();
        return false;
    }   
});

解决方案

Here you go:

public boolean onTouch(View v, MotionEvent event) {
    switch (event.getAction()) {
    case MotionEvent.ACTION_DOWN:
        //some code....
        break;
    case MotionEvent.ACTION_UP:
        v.performClick();
        break;
    default:
        break;
    }
    return true;
}