Android keyboard issue that appears when action starts

I am developing an Android application and have a problem in the following scenario:

  • in the first activity list, the user touches the list item
  • A dialog box appears listing the subcategories for the selected item.
  • user selects a subcategory
  • The next action starts with the selected item and subcategory. Note that:
    • the first item on the next activity screen is the EditText field
    • the second element of the next action is the button and in the method onCreate()I focused on the buttonspeakNameBtn.requestFocus();

and here the problem becomes: if the user selects a subcategory in step 3 by touching it in the list, on the next screen the user sees a pop-up menu, and the field EditText, and not the button, has focus.

Question. How can I prevent this keyboard from appearing?

It seems that the touch event in the first dialogue of the screen somehow extended to the next action. If I use the ball to select a subcategory, rather than touching it, everything works as expected - the focus is on the button and I don’t see the keyboard.

Any thoughts would be greatly appreciated.

+3
source share
1 answer

Put this above EditText:

<!-- Dummy item to prevent AutoCompleteTextView from receiving focus -->
<LinearLayout
    android:focusable="true" android:focusableInTouchMode="true"
    android:layout_width="0px" android:layout_height="0px"/>

I took it from the forum a few months ago, and it works fine ... could not find it again, so I am inserting it from one of my projects.

+8

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


All Articles