Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Custom view 'ImageButton' has setOnTouchListener called on it but does not override performClick

Tags:

Well, I know there are some questions regarding this warning, but i still cannot figure out how to get rid of this. I don't want to implement the OnTouchListener interface on class level, because there are many buttons and i prefer to keep every piece of code on his own "space". I added performClick() after ACTION_UP case but the warning still persist.

enter image description here

Thank you

send.setOnTouchListener(new View.OnTouchListener() {
                @Override
                public boolean onTouch(View view, MotionEvent motionEvent) {
                    switch (motionEvent.getAction()){
                        case MotionEvent.ACTION_UP:
                            view.performClick();
                            break;
                        default:
                            break;
                    }
                    return true;
                }
            });
like image 260
AeonDave Avatar asked Sep 09 '17 21:09

AeonDave


2 Answers

Your code is OK, if you are sure that your code works like you want, you can just disable this kind of warnings in: File -> Settings -> Editor -> Inspections -> Android -> Lint -> Accessibility -> Accessibility in Custom Views

like image 87
Dan Avatar answered Sep 28 '22 09:09

Dan


Basically it suggests that you should subclass ImageButton and override its performClick() method but it's not worth the hassle just suppress this warning using @SuppressLint("ClickableViewAccessibility") in your method or just disable this warning like I did.

like image 39
ThanosFisherman Avatar answered Sep 28 '22 11:09

ThanosFisherman