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


This Question and Answer are collected from stackoverflow and tested by JTuto community, is licensed under
CC BY-SA 2.5. - CC BY-SA 3.0. - CC BY-SA 4.0.

Issue

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

Answered By – Saif

people found this article helpful. What about you?