Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android marker: onTouch should call View#performClick when a click is detected

I have a functional code but after last SDK update I'm getting this warning:

Multiple markers at this line
- onTouch should call View#performClick when a click is detected
- implements 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");
    }
});

My code is working properly but if I uncoment v.performClick(); to remove warning I get unwanted behaviour. Why am I getting this warning and is there going to be some problems if I discard it and leave the code as is?

EDIT:

this is my log when I click on button:
"next", "touch"
"next", "touch"
"next", "click"

and this is with v.performClick()
"next", "click"
"next", "touch"
"next", "click"
"next", "touch"

"next", "click"

like image 599
mgulan Avatar asked Aug 19 '14 18:08

mgulan


1 Answers

You should put the

v.performClick();

inside the second if:

if (event.getAction() == MotionEvent.ACTION_UP ....) {
    v.performClick();
    detect.setEnabled(false);
}
like image 50
lenooh Avatar answered Sep 27 '22 19:09

lenooh