I have a checkbox with onTouchListener, and in this listener, I have switch with these cases:
MotionEvent.ACTION_DOWNMotionEvent.ACTION_UPMotionEvent.ACTION_CANCELWhen I don't have view.performClick() in the ACTION_UP case, I get a lint warning:
onTouch should call View#performClick when a click is detected
But it causes my method to not work:
public void touchCheckBox(View view) {
CheckBox checkBox = (CheckBox) view.findViewById(R.id.checkbox);
checkBox.performClick();
}
My method works fine if I add view.performClick() in ACTION_DOWN too.
My code for touchCheckBox() is:
public boolean onTouch(View view, MotionEvent motionEvent) {
boolean isEventConsumed;
switch (motionEvent.getAction()) {
case MotionEvent.ACTION_DOWN:
row.setBackgroundColor(mContext.getResources().getColor(R.color.blueSelection));
isEventConsumed = true;
break;
case MotionEvent.ACTION_UP:
view.performClick();
row.setBackgroundColor(mContext.getResources().getColor(R.color.white));
touchCheckBox(row);
isEventConsumed = true;
break;
case MotionEvent.ACTION_CANCEL:
row.setBackgroundColor(mContext.getResources().getColor(R.color.white));
isEventConsumed = true;
break;
default:
isEventConsumed = false;
break;
}
return isEventConsumed;
}
});
Is view.performClick() necessary in the ACTION_UP case, or I can suppress the lint warning?
https://code.google.com/p/android-developer-preview/issues/detail?id=1394
It was reported as bug, I think you just surpress the warning.
Well, try this:
public boolean onTouch(View v, MotionEvent event) {
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
// stuffs
break;
case MotionEvent.ACTION_UP:
v.performClick();
break;
default:
break;
}
return true;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With