3

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

  1. on first activity list user touches a list item
  2. a dialog window with a list of subcategories for the selected item pops up
  3. the user selects a subcategory
  4. the next activity starts with the selected item and subcategory. Note that:
    • the first element on the next activity screen is an EditText field
    • the second element on the next activity is a button and in the onCreate() method I set focus on the button speakNameBtn.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 the popup keyboard and the EditText field, not the button, has the focus.

Question - how can I prevent that keyboard to show up?

It seems that touch event on the first screen dialog somehow propagated to the next activity. If I use the ball to select a subcategory instead of touching it, everything works as expected - the focus set on the button and I do not see the keyboard.

Any thoughts would be greatly appreciated.

Mathew Thompson
  • 55,877
  • 15
  • 127
  • 148
Damir
  • 31
  • 2

1 Answers1

8

Put this above the 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 a forum several months ago and it works fine... couldn't find it again so I'm pasting it from one of my projects.

Cristian
  • 198,401
  • 62
  • 356
  • 264