How to prevent android form from skipping sections in the form?

I have an Android form consisting of some editText and spinner widget. When you start at the first edittext and press next on the on-screen keyboard, it skips the spinners and goes straight to the next edittext entry. How can I prevent missing entries no matter what post types they are? for example spinner, edittext, dialog, etc. Here's my layout:

<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>

      

+3


source to share


1 answer


You must refer to the action of the next button yourself.

Here's how to simulate a click on your Spinner when the user clicks Next on the EditText in front of the Spinner and selects the following EditText to select one of the Spinner items:



// Set the EditText preceding the Spinner 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 item selection behaviour to move focus to the following View
   (EditText, other Spinner, etc) on Spinner 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) {
    }
});

      

Note that if the user re-selects the value previously selected on the Spinner, onItemSelected()

it will not be called, but there are workarounds to this.

+1


source







All Articles