Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can you set "tab order" in XML Layout?

Tags:

android

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"/>
like image 902
dalesit Avatar asked Feb 19 '11 03:02

dalesit


People also ask

What is tab order in a form?

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.


3 Answers

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.

like image 168
EricLarch Avatar answered Oct 13 '22 22:10

EricLarch


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.

like image 38
Andrew Mackenzie Avatar answered Oct 13 '22 21:10

Andrew Mackenzie


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.

like image 12
Jasper de Vries Avatar answered Oct 13 '22 23:10

Jasper de Vries