Android XML - move between EditText fields

I have 2 fragments on which there are several EditText blocks. They are both laid out similar, but it is very strange that 1 will be inserted between the EditText fields, and the other will not.

This is the one I'm having problems with:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/loginparent" android:layout_width="match_parent" android:layout_height="match_parent" android:background="#ff008DFF" > <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:layout_centerHorizontal="true" android:layout_marginTop="20dip" android:background="#ff008DFF" android:orientation="vertical" > <ImageView android:id="@+id/imageView2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginBottom="40dip" android:contentDescription="@string/logoDesc" android:src="@drawable/logo1" /> <EditText android:id="@+id/usernameLog" android:layout_width="match_parent" android:layout_height="wrap_content" android:ems="10" android:focusable="true" android:focusableInTouchMode="true" android:hint="@string/username" android:imeOptions="actionNext" android:singleLine="true" android:textSize="14sp" /> <EditText android:id="@+id/passwordLog" android:layout_width="match_parent" android:layout_height="wrap_content" android:hint="@string/password" android:imeOptions="actionDone" android:inputType="textPassword" android:singleLine="true" android:textSize="14sp" /> <Button android:id="@+id/loginButton" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="@string/login" /> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="20dip" > <TextView android:id="@+id/textView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:focusable="false" android:focusableInTouchMode="false" android:text="@string/newuser" android:textColor="#ffffffff" android:textSize="14sp" /> <Button android:id="@+id/viewSignupBtn" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="@string/signup" /> </LinearLayout> </LinearLayout> <ProgressBar android:id="@+id/progressBarLog" style="?android:attr/progressBarStyleLarge" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerHorizontal="true" android:layout_centerVertical="true" android:focusable="false" android:focusableInTouchMode="false" android:padding="70dip" android:visibility="gone" /> </RelativeLayout> 

When I enter EditText from the first field, the focus disappears, and then on the second tab it moves the focus to the second field. The same thing if I click focus, then again overlay the tab and appear on the button below.

Nothing special happens in Fragment onCreateView, except for pointers to EditText fields. As I said, I have a second view, very similar, that works great.

When I insert a tab, I notice that I get these warnings appearing in Logcat:

 04-24 19:31:29.695: D/InputEventConsistencyVerifier(2040): KeyEvent: ACTION_UP but key was not down. 04-24 19:31:29.695: D/InputEventConsistencyVerifier(2040): in android.support.v4.app.NoSaveStateFrameLayout@40f365b8 04-24 19:31:29.695: D/InputEventConsistencyVerifier(2040): 0: sent at 4325570000000, KeyEvent { action=ACTION_UP, keyCode=KEYCODE_TAB, scanCode=15, metaState=0, flags=0x8, repeatCount=0, eventTime=4325570, downTime=4325514, deviceId=0, source=0x101 } 04-24 19:31:31.076: D/InputEventConsistencyVerifier(2040): KeyEvent: ACTION_UP but key was not down. 04-24 19:31:31.076: D/InputEventConsistencyVerifier(2040): in android.widget.EditText@40f78e98 04-24 19:31:31.076: D/InputEventConsistencyVerifier(2040): 0: sent at 4326945000000, KeyEvent { action=ACTION_UP, keyCode=KEYCODE_TAB, scanCode=15, metaState=0, flags=0x8, repeatCount=0, eventTime=4326945, downTime=4326889, deviceId=0, source=0x101 } 04-24 19:31:32.255: D/InputEventConsistencyVerifier(2040): KeyEvent: ACTION_UP but key was not down. 04-24 19:31:32.255: D/InputEventConsistencyVerifier(2040): in android.widget.EditText@40f73678 04-24 19:31:32.255: D/InputEventConsistencyVerifier(2040): 0: sent at 4328123000000, KeyEvent { action=ACTION_UP, keyCode=KEYCODE_TAB, scanCode=15, metaState=0, flags=0x8, repeatCount=0, eventTime=4328123, downTime=4328053, deviceId=0, source=0x101 } 

EDIT -----------------

Well, as suggested in the comments, I added onFocusChanged listeners to all the views (I laid them all and added a listener) and launched what the view is. Each time I insert a tab, I get a log, but it's strange, I paste in the first EditText field, and the log says that there is focus in the editText field, I find the tab again and the focus is lost, but the log says that in the same the EditText window has focus! The tab again, and the second receives focus, and the log says that the correct identifier, the tab focus is lost again, but again the log says that the 2nd EditText window has focus, even if it is not!

Very strange behavior.

+6
source share
2 answers

As @Delyan points out, you should be able to add an XML attribute to control this behavior. However, you can try using one of the other android:nextFocus____ attributes, for example android:nextFocusForward . A complete list of these attributes is available here and below.

+4
source

You can use android:nextFocusDown to override the order of the tabs. In general, the tab looks down, the shift + tab looks up, and the directional keys / trackball start the search left / right.

+1
source

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


All Articles