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 current row.
When the user hits tab it takes them to the next field below, not the next field to the right.
Is there a way in the layout to set the tab order or is it only done programatically?
If it can only be done in Java, how exactly is it done?
Thanks for the tip on NextFocusRight but it didn' seem to work (or I did something wrong)
Here is the code I used. I have to add the imeoptions to get the "next" button to show up in my emulator. Do you see anything wrong with the way I did this?
<EditText
android:id="@+id/bikeHHT"
android:layout_width="50dip"
android:layout_height="40dip"
android:textSize="14px"
android:maxLength="2"
android:nextFocusLeft="@+id/bikeMMT"
android:imeOptions="actionNext"
android:layout_column="1"/>
<EditText
android:id="@+id/bikeMMT"
android:layout_width="50dip"
android:layout_height="40dip"
android:textSize="14px"
android:nextFocusRight="@+id/bikeSST"
android:imeOptions="actionNext"
android:maxLength="2"/>
Tab Order is the order or sequence that the cursor moves from field to field. Initially, the tab order is determined by the order in which the fields are added to the form.
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.
I also notice that in your reference:
android:nextFocusRight="@+id/bikeSST"
The "+" character is required if you have not yet defined that id, if perhaps the element you reference is lower in the .xml file.
Otherwise you if it's already defined above (or included) then you can omit the "+" char:
android:nextFocusRight="@id/bikeSST"
An advantage of not using the "+" when you are referencing an ID that should already exist, is that the IDE and Lint checks can detect an error case: That you are referring to an ID that in fact does not exist.
If you include the "+", then you are creating it if doesn't exist and this check cannot be performed.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With