专注于自定义对话框中的最后一个编辑文本不起作用
问题描述:
在我的应用程序中,我使用了一个带有三个编辑文本的自定义对话框(android.app.Dialog)。当我按下SoftKeyboard上的下一个按钮时,我可以从第一个EditText到第二个EditText设置焦点,但它没有将焦点设置在第三个EditText上。我已经尝试设置nextFocusForward或nextFocusDown等,但它仍然不起作用。专注于自定义对话框中的最后一个编辑文本不起作用
这里是我的自定义对话框的XML布局:
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fillViewport="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<ImageView
android:id="@+id/addcard_image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="16dp"
android:adjustViewBounds="true"
android:scaleType="fitCenter"
android:src="@drawable/dialog_addcard_info" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<EditText
android:id="@+id/addcard_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:hint="@string/name"
android:inputType="text"
android:lines="1"
android:maxLines="1"
android:scrollHorizontally="true" />
<EditText
android:id="@+id/addcard_number"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:layout_marginTop="8dp"
android:hint="@string/number"
android:inputType="number"
android:maxLength="16"
android:scrollHorizontally="true"/>
<EditText
android:id="@+id/addcard_pin"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:layout_marginTop="8dp"
android:hint="@string/pin"
android:inputType="numberPassword"
android:maxLength="4"
android:textSize="14sp"
android:scrollHorizontally="true"/>
</LinearLayout>
<TextView
android:id="@+id/addcard_errormessage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="25dp"
android:paddingLeft="16dp"
android:paddingRight="16dp"
android:text="@string/error"
android:textColor="#ff0000"
android:textStyle="bold"
android:visibility="gone" />
<Button
android:id="@+id/addcard_verify"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="16dp"
android:text="@string/verify" />
</LinearLayout>
有没有人有一个想法,为什么我不能将焦点设置在第三的EditText? 在此先感谢。
答
试试这个在您的代码:)
<EditText
android:id="@+id/addcard_number"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:layout_marginTop="8dp"
android:hint="@string/number"
android:inputType="number"
android:maxLength="16"
android:imeOptions="actionNext" // try this one
android:nextFocusDown="@+id/addcard_errormessage" // and add this one
android:scrollHorizontally="true"/>
+1
只是添加imeOptions做了伎俩,感谢G.Dator和Sakchham Sharma – Distra
+0
不客气。 –
添加'机器人:imeOptions = “actionNext”'前两个的EditText应该做的。我想你正在寻找的是[这](https://developer.android.com/reference/android/widget/TextView.html#attr_android:imeOptions) –