Android: nextFocusForward ignored in layout

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

The documentation says that android: nextFocusForward = TARGET_ID should do this trick. But this is ignored on all of our test devices. Some older devices are 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? I just can’t understand. Thank you very much!

+3
source share
2 answers

Try the following FocusDown. I do not 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.

+9
source

I tried setting nextFocusDown, nextFocusForward, nextFocusRight, but none of them worked. I got his work by listening to the action of the editor and programmatically focusing on the next EditText.

  mFirstName.setOnEditorActionListener(new TextView.OnEditorActionListener() { @Override public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { mLastName.requestFocus(); return true; } }); 
0
source

Source: https://habr.com/ru/post/1241031/


All Articles