Can you set the “tab order” in the XML layout?

I have users with tablets that have a tab key on their soft keyboard. I use a table view and have 3 EditText fields on the same line as EditText fields below the current row.

When the user clicks the tab, he moves them to the next field below, and not the next field to the right.

Is there a way in the layout to set the order of the tabs or is this done only programmatically?

If this can only be done in Java, how exactly is this done?

Thanks for the tip on NextFocusRight, but it didn’t work (or I did something wrong)

Here is the code I used. I need to add images to display the “next” button in my emulator. Do you see something wrong with the way I did it?

<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"/> 
+47
android
Feb 19 2018-11-11T00:
source share
7 answers

Replace android:nextFocusLeft with android:nextFocusDown . The “next” soft button or TAB key searches for the next “down” focus, not left or right.

+84
Feb 21 '11 at 16:33
source share

I also notice that in your link:

 android:nextFocusRight="@+id/bikeSST" 

The "+" symbol is required if you have not yet defined this identifier, if, possibly, the element you are referencing is smaller in the XML file.

Otherwise, you, if it is already defined above (or included), you can omit the char + character:

 android:nextFocusRight="@id/bikeSST" 

The advantage of using "+" when you refer to an identifier that must already exist is that the IDE and Lint checks can detect an error case: that you mean an identifier that does not actually exist.

If you include "+", you create it if it does not exist, and this check cannot be performed.

+34
Apr 07 '11 at 16:24
source share

Have you checked the android:imeOptions="actionNext" attribute android:imeOptions="actionNext" for EditText?

It replaces the name of the enter key with "Next" on the virtual keyboard and clicking on it - the focus transitions to the next field.

In your layout you will do something 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(); 

You decide which field will request the following.

+9
Feb 19 '11 at 5:23
source share

For me, android:nextFocusUp , android:nextFocusRight , android:nextFocusDown and android:nextFocusLeft did not work, but android:nextFocusForward did work.

See Support for keyboard navigation, Handle tab navigation .

+8
Aug 21 '13 at 9:10
source share

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 greatly simplifies the implementation of the form.

The problem is that damn life remembers what the hell ...

Be sure to check the properties of android: nextFocus * xml. The normal action of the form is down. But perhaps there is a button on the right so that you want to get the next focus (for example, entering the game or the like).

http://developer.android.com/reference/android/view/View.html#attr_android:nextFocusDown

Some software options are also available there:

http://developer.android.com/reference/android/view/View.html#setNextFocusDownId(int )

+4
Feb 19 '11 at 4:21
source share

Perhaps you are looking for the attributes android: nextFocusRight, android: nextFocusLeft, android: nextFocusUp and android: nextFocusDown. If, by default, the tab button moves the focus down to the second line, I would think you could set android: nextFocusDown to the view identifier that you want to get in focus. Then, when the user clicks the tab, wold moves the focus to any view you specify, although in this case it is located to the right of the current view, not lower.

+3
Feb 19 2018-11-11T00:
source share

Replace android:nextFocusLeft with android:nextFocusForward .

0
01 Oct '13 at 17:54 on
source share



All Articles