我有一个Android表单,包含一些editText和spinner小部件。当您从第一个edittext开始并在屏幕键盘上点击“next”时,它会跳过微调器并直接进入下一个edittext输入。如何禁止跳过条目,无论它们是什么类型的条目?即,微调器,编辑文本,对话框等。这是我的布局:
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/ScrollView01" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:scrollbars="vertical"
android:background="@drawable/flagbackground" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="490dp"
android:gravity="center"
android:orientation="vertical" >
<TextView android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/vetn"
android:textAppearance="?android:attr/textAppearanceMedium" />
<EditText android:id="@+id/etVetName"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:inputType="text" />
<TextView android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/vetdob"
android:textAppearance="?android:attr/textAppearanceMedium" />
<EditText android:id="@+id/etVetDob"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:inputType="date" />
<TextView
android:layout_width="318dp"
android:layout_height="wrap_content"
android:text="@string/phone"
android:textAppearance="?android:attr/textAppearanceMedium" />
<EditText android:id="@+id/etVetPhone"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="top"
android:inputType="phone"
android:hint="@string/optional"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/branch"
android:textAppearance="?android:attr/textAppearanceMedium" />
<Spinner
android:id="@+id/SpinnerBranchType"
android:layout_height="wrap_content"
android:prompt="@string/branch"
android:layout_width="fill_parent"
android:entries="@array/branchtypelist">
</Spinner>
<TextView android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/gender"
android:textAppearance="?android:attr/textAppearanceMedium" />
<Spinner
android:id="@+id/SpinnerSexType"
android:layout_height="wrap_content"
android:prompt="@string/sex"
android:layout_width="fill_parent"
android:entries="@array/sexlist">
</Spinner>
<TextView android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/discharge"
android:textAppearance="?android:attr/textAppearanceMedium" />
<Spinner
android:id="@+id/DischargeType"
android:layout_height="wrap_content"
android:prompt="@string/distype"
android:layout_width="fill_parent"
android:entries="@array/dischargelist">
</Spinner>
<TextView android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/dd214"
android:textAppearance="?android:attr/textAppearanceMedium" />
<Spinner
android:id="@+id/dd214Response"
android:layout_height="wrap_content"
android:prompt="@string/dd214"
android:layout_width="fill_parent"
android:entries="@array/yesnoanswer" >
</Spinner>
<TextView android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/home"
android:textAppearance="?android:attr/textAppearanceMedium" />
<Spinner
android:id="@+id/homelessResponse"
android:layout_height="wrap_content"
android:prompt="@string/homeless"
android:layout_width="fill_parent"
android:entries="@array/yesnoanswer">
</Spinner>
<TextView android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/weekend"
android:textAppearance="?android:attr/textAppearanceMedium" />
<Spinner
android:id="@+id/ngResponse"
android:layout_height="wrap_content"
android:prompt="@string/ngrsrv"
android:layout_width="fill_parent"
android:entries="@array/yesnoanswer">
</Spinner>
<TextView android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/benefit"
android:textAppearance="?android:attr/textAppearanceMedium" />
<Spinner
android:id="@+id/benefitResponse"
android:layout_height="wrap_content"
android:prompt="@string/benefits"
android:layout_width="fill_parent"
android:entries="@array/yesnoanswer">
</Spinner>
<TextView android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/foodstamps"
android:textAppearance="?android:attr/textAppearanceMedium" />
<Spinner
android:id="@+id/foodResponse"
android:layout_height="wrap_content"
android:prompt="@string/food"
android:layout_width="fill_parent"
android:entries="@array/yesnoanswer">
</Spinner>
<TextView android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/cashaid"
android:textAppearance="?android:attr/textAppearanceMedium" />
<Spinner
android:id="@+id/cashResponse"
android:layout_height="wrap_content"
android:prompt="@string/cash"
android:layout_width="fill_parent"
android:entries="@array/yesnoanswer">
</Spinner>
<TextView android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/ref"
android:textAppearance="?android:attr/textAppearanceMedium" />
<EditText android:id="@+id/etRefer"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:hint="@string/refhint"
android:inputType="text" />
<TextView android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/comment"
android:textAppearance="?android:attr/textAppearanceMedium" />
<EditText
android:id="@+id/etCommentBody"
android:layout_height="wrap_content"
android:hint="@string/hint"
android:inputType="textMultiLine"
android:lines="5"
android:layout_width="fill_parent">
</EditText>
<Button android:id="@+id/btnOK"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/submit"
android:textAppearance="?android:attr/textAppearanceMedium" />
</LinearLayout>
答案 0 :(得分:1)
您必须自己处理“下一步”按钮的操作。
以下是当用户在Spinner前面的EditText上单击Next并在选择其中一个Spinner项目时选择以下EditText时,如何模拟Spinner上的单击:
// Set the EditText preceding the Spinner's next action to click the Spinner
editTextBeforeSpinner.setOnEditorActionListener(new TextView.OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
if (actionId == EditorInfo.IME_ACTION_NEXT) {
spinner.performClick();
return true;
}
return false;
}
});
// This is to avoid onItemSelected() being called on setup
spinner.setSelection(0, false);
/* Set Spinner's item selection behaviour to move focus to the following View
(EditText, other Spinner, etc) on Spinner's item selection */
spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
editTextAfterSpinner.requestFocus();
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
}
});
请注意,如果用户重新选择之前在微调器上选择的值,则不会调用onItemSelected()
,但会有workarounds。