I\'ve got users with tablets that have a tab key on their soft keyboard. I am using a table view and have 3 EditText Fields in one row with EditText fields below the curren
There is a better way. There is an XML argument that you can put in your layout that automatically moves the cursor through each EditText
as the user completes them. This allows for much easier form implementation.
Problem is, for the damn life remember what hell it is...
Be sure to check out the android:nextFocus* xml properties. Normal form action is to go down. But perhaps there's a button to the right that you'd like to receive next focus (like hitting enter or similar).
http://developer.android.com/reference/android/view/View.html#attr_android:nextFocusDown
There's also some programatic options available:
http://developer.android.com/reference/android/view/View.html#setNextFocusDownId(int)
You might be looking for the attributes android:nextFocusRight, android:nextFocusLeft, android:nextFocusUp, and android:nextFocusDown. If the default behavior of the tab button is moving focus down to the second row, then I would think you could set android:nextFocusDown to the id of the view that you want to get focus next. Then when the user presses tab it wold move focus to whatever view you specify, even though in this case it happens to be to the right of the current view, and not below it.
Replace android:nextFocusLeft
with android:nextFocusForward
.
Replace android:nextFocusLeft
by android:nextFocusDown
. The "next" soft button or the TAB key is looking for the next "down" focus and not left or right.
Did you check android:imeOptions="actionNext"
attribute for the EditText ?
It replaces the name of the enter key with "Next" in the virtual keyboard and by clicking on it - focus jumps to the next field.
In your layout, you would do things like this
<EditText
...
android:text="Field 1"
android:imeOptions="actionNext" />
<EditText
...
android:text="Field 2"
android:imeOptions="actionNext" />
And in Java
TextView field2 = (TextView) field1.focusSearch(View.FOCUS_RIGHT);
field2.requestFocus();
It's up to you to decide which field will request focus next.
For me android:nextFocusUp
, android:nextFocusRight
, android:nextFocusDown
and android:nextFocusLeft
were not working, but android:nextFocusForward
did work.
See Supporting Keyboard Navigation, Handle Tab Navigation.