0

I have an EditText which I have created a screen keyboard so I have deactivated the system keyboard. But the method I have underlines everything in yellow and gives me the following warning:

Custom view has setOnTouchListener called on it but does not override performClick If a View that overrides onTouchEvent or uses an OnTouchListener does not also implement performClick and call it when clicks are detected, the View may not handle accessibility actions properly. Logic handling the click actions should ideally be placed in View#performClick as some accessibility services invoke performClick when a click action should occur.

I know I could easily get rid of this error using the @SuppressLint("ClickableViewAccessibility") tag but I don't want to do it this way, I want to fix the warning in a more correct way, solutions?

Ryan M
  • 18,333
  • 31
  • 67
  • 74
Ludiras
  • 338
  • 3
  • 20
  • This warning clearly gives an explanation. I found out that only by using `@SuppressLint("ClickableViewAccessibility")` you can suppress the warning. – Rahul Agrawal Dec 16 '19 at 16:46
  • It's not the only way to do it. I doubt it's the only way to do it because then you're not giving blind people any chance, and it's the origin of this warning as I understand it. – Ludiras Dec 16 '19 at 17:42

1 Answers1

1

The issue it's warning you about is that you've only handled the case of a user touching the screen, but there are many other ways of interacting with the EditText, such as keyboards or accessibility services.

For your specific use-case of preventing the keyboard from showing, you can instead use setShowSoftInputOnFocus(true) to prevent the soft keyboard from displaying. This method is available on API 21+, though some people have suggested that you may be able to get it to work through unofficial methods on earlier versions.

If you can't or don't want to do that, you should also override performClick and do the same thing you're doing in onTouchEvent, whatever that may be. If you do that, make sure that you test with a keyboard and/or accessibility service to make sure that your app is still usable for those users.

Ryan M
  • 18,333
  • 31
  • 67
  • 74