Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

EditText tab order

I have a layout consisting of a LinearLayout with a vertical orientation containing several EditTexts. The virtual keyboard of each of these EditTexts has a "next" button. Pressing the "next" button moves the cursor to the EditText below it.

However, somewhere in the middle of these EditTexts I added another LinearLayout, this one horizontal, with a few EditTexts inside of it. This leaves me with several EditTexts stacked vertically, then a few EditTexts on 1 row horizontal to each other, and then more EditTexts stacked vertically underneath.

The tab order begins as before, but when it reaches the first EditText of the horizontal LinearLayout, hitting the "next" button doesn't move to the next EditText to its right. It skips the two to the right and moves down to the EditText below.

How can I achieve the tab order I desire?

I've attached an image, a true work of art really, of the order I want

like image 403
Andrew Avatar asked Mar 13 '12 19:03

Andrew


2 Answers

use android:nextFocusDown="your next id edit text". Example :

    ....
    <LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content" 
    android:orientation="horizontal">
    <EditText
        android:id="@+id/editText1"
        android:layout_width="200dp"
        android:layout_height="wrap_content"
        android:nextFocusDown="@+id/editText2" />
    <EditText
        android:id="@+id/editText2"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />
    </LinearLayout>
    ....
like image 50
pangestu Avatar answered Nov 13 '22 16:11

pangestu


Look into using the XML tags nextFocusDown/Forward/etc. Documentation

like image 43
dymmeh Avatar answered Nov 13 '22 14:11

dymmeh