How to keep DropDownList from AutoCompleteTextView open after pressing the back key?

I use AutoCompleteTextView in my work, and I need the DropDownList to be displayed all the time (this is the only view in the window), even after pressing the Back key. Instead, I need to reject the soft keyboard.

I tried to override the Activity onBackPressed method, but it is not used at all, so the BackPressed event is handled somewhere above. So I tried to figure out where, but AutoCompleteTextView does not have the onBackPressed method set.

Any tips?

+4
source share
2 answers

You can create your own AutoCompleteTextView method and override the onKeyPreIme method (int keyCode, KeyEvent event)

I also realized that this method is called 2 times, I only run my code a second time. Here is an example:

@Override public boolean onKeyPreIme(int keyCode, KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_BACK && event.getAction() == 1) { //add your code here return true; } return super.onKeyPreIme(keyCode, event); } 
+2
source

You can try this

 @Override public boolean onKeyDown(int keyCode, KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_BACK) { //Your back key press logic } return true; } 

Remember to return true to prevent this event from further propagating, or false to indicate that you have not processed this event and should continue to distribute it.

0
source

Source: https://habr.com/ru/post/1401625/


All Articles