nizam.sp
nizam.sp

Reputation: 4072

AutoCompleteTextView cursor should move to next AutoCompleteTextView/EditTextBox on select of Suggestions

When I click the Suggestions of an AutoCompleteTextView, I want the cursor to move on to the next EditBox or AutoCompleteTextView that is available.

I have attached my layout and my app image file below. In this Image, If I select the Chennai Central (MAS), I want to fill the data in From TextBox and move to the next TO TextBox.

Image

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="horizontal"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:padding="5dp">
    <AutoCompleteTextView android:id="@+id/autocompleteFrom"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:hint="From Station"
        android:singleLine="true"
        android:inputType="textNoSuggestions"
        android:layout_marginLeft="5dp"
        android:imeOptions="actionNext"
        />

    <AutoCompleteTextView android:id="@+id/autocompleteTo"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_below="@id/autocompleteFrom"
        android:hint="To Station"
        android:singleLine="true"
        android:inputType="textNoSuggestions"
        android:layout_marginLeft="5dp"
        android:imeOptions="actionDone"
        />

    <Button android:text="Find Trains"
        android:id="@+id/findTrains"
        android:layout_below="@id/autocompleteTo"

        android:layout_width="wrap_content"
        android:layout_height="wrap_content"/>

</RelativeLayout>

Any help is much appreciated!

Upvotes: 1

Views: 2717

Answers (1)

KunamiPT
KunamiPT

Reputation: 112

If I understood the question,

    AutoCompleteTextView acFrom = (AutoCompleteTextView) findViewById(R.id.autocompleteFrom )
        acFrom.setOnItemClickListener(new OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> p, View v, int pos, long id) {
                //TODO: set focus on next view
                AutoCompleteTextView acTo = (AutoCompleteTextView) findViewById(R.id.autocompleteTo)
                acTo.setFocusableInTouchMode(true); 
                acTo.requestFocus()
            }
        });

Upvotes: 3

Related Questions