Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

android:nextFocusForward is ignored in layout

I have an android xml layout and i want to specify the focus order of the fields, when user presses next on the keyboard.

Documentation says, that android:nextFocusForward=TARGET_ID should do that trick. But it is ignored on all our testing devices. Some old devices running 2.3 and new Nexus devices running 4.1.

<LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal" >

        <EditText
            android:textCursorDrawable="@null"
            android:id="@+id/firstname"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginBottom="6dp"
            android:layout_marginTop="6dp"
            android:layout_weight="1"
            android:singleLine="true"
            android:background="#00000000"
            android:textColor="#000"
            android:nextFocusForward="@+id/lastname"
            android:padding="2dp"/>

        <EditText
            android:textCursorDrawable="@null"
            android:id="@+id/lastname"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginBottom="6dp"
            android:layout_marginTop="6dp"
            android:layout_weight="1"
            android:background="#00000000"
            android:singleLine="true"
            android:textColor="#000"
            android:padding="2dp"/>
    </LinearLayout>

What am i doing wrong here??? Just can't figure it out. Thanks a lot!

like image 363
Sigi Avatar asked Feb 13 '13 09:02

Sigi


People also ask

How to set LinearLayout in android studio?

To create a linear layout in which each child uses the same amount of space on the screen, set the android:layout_height of each view to "0dp" (for a vertical layout) or the android:layout_width of each view to "0dp" (for a horizontal layout). Then set the android:layout_weight of each view to "1" .

Which XML attribute can be used to put a view in front of other views?

bringToFront()” method will let you a perfect indicator view :) Also, there is another option to use a parent-children relationship views.

What are the different features that we can use of linear layout while designing the application?

Some Important Attributes of LinearLayout It can be horizontal or vertical. It specifies how an object should position its content on its X and Y axes. Possible values are – center_vertical, fill, center, bottom, end, etc. Sets the gravity of the View or Layout relative to its parent.


1 Answers

Try nextFocusDown as well. I don't fully understand the rules, but it seems that the behavior depends on the layout of the EditTexts, and where the cursor position is relative to the next field.

like image 57
Sofi Software LLC Avatar answered Sep 22 '22 14:09

Sofi Software LLC