I'm using 4 EditText
fields and 2 spinners in an activity. The order of these components are 2 EditText
, then 2 spinners and then 2 EditText
fields.
The problem occurs when I transfer focus (with the help of soft keyboard next button) from EditText
to spinner, spinner does not get the focus and the focus is transferred to the next EditText
field that was placed after the spinners.
I have used requestfocus() on spinner, but it did not work.
How do I make sure the spinner gets focus?
I managed to find a solution other then repositioning my Spinner. In the EditText before the spinner, add this listener:
You also need to add these line to able spinner to get focus:
My hideKeyboard function was just a visual detail that I wanted to add so the keyboard get hidden:
Hope I have helped in this tricky question.
The flag
InputMethodManager.HIDE_NOT_ALWAYS
can be found in the documentation.This is a shot in the dark, but try setting the focusable property (in XML or in code; whatever way you are doing it) to true on the spinner.
http://developer.android.com/reference/android/view/View.html#attr_android:focusable
EDIT: Also, see this question: Can't manage to requestFocus a Spinner
I just had the same problem. I solved it using the nextFocusDown/Up/Left/Right properties.
But why this is even neccessary... beats me.
Thanks, I have solved by doing the following:
onCreate
method) just to make sure that my code gets executed firstI used the following: