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!
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" .
bringToFront()” method will let you a perfect indicator view :) Also, there is another option to use a parent-children relationship views.
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.
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.
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