onTouchListener warning: onTouch should call View#performClick when a click is detected

Trzy Gracje picture Trzy Gracje · Jul 25, 2014 · Viewed 59.6k times · Source

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 mean? 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;
    }   
});

Answer

Secko picture Secko · Aug 13, 2014

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;
}