javaandroidandroid-studioautocompletetextview

How to set AutoCompleteTextView with his first value from the arrayAdapter with inputType of none


So I have this AutoCompleteTextView

            <com.google.android.material.textfield.TextInputLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
               style="@style/Widget.MaterialComponents.TextInputLayout.FilledBox.ExposedDropdownMenu">

                <AutoCompleteTextView
                    android:id="@+id/actv_choices"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:hint="Choose"
                    android:inputType="none"
                    android:text="Handicapped "/>
            </com.google.android.material.textfield.TextInputLayout>

This is how it looks visualy

enter image description here

I want to achieve that when the client starts the activity it will initialize the value of the AutoCompleteTextView to be one of the values of my list values that I set in the adapter for example, I got these values enter image description here

And I want that when the client opens the app it will set the value to be for example the second value like that by default enter image description here

How can I achieve this?


Solution

  • After setting the adapter for your autoComplete textView you can do this:

    Your custom data list ex. List<YourCustomModel> data

    actvChoices.setText(data.get(index));