Hi All, I am trying to implement dropdown with cus...
# android
s
Hi All, I am trying to implement dropdown with custom layout like below image but i can't able to set selected value on AutoCompleteTextView because AutoCompleteTextView have only 1 method setText but i am displaying custom list so i can't able to set value like listview so could you please provide me your view how i can change AutoCompleteTextView design
stackoverflow 4
r
I use this for the UI
Copy code
<com.google.android.material.textfield.TextInputLayout
                android:id="@+id/spin"
                style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox.ExposedDropdownMenu"
                android:layout_width="0dp"
                android:layout_weight="5"
                android:layout_height="70dp">


                <AutoCompleteTextView
                    android:layout_width="match_parent"
                    android:layout_height="50dp"
                    android:inputType="none" />

            </com.google.android.material.textfield.TextInputLayout>
and
Copy code
private fun configureSpinnerAdapter() {
        val adapter = ArrayAdapter.createFromResource(
            this,
            R.array.gender_array,
            android.R.layout.simple_spinner_item
        ).also { adapter ->
            adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item)
            (spin.editText as? AutoCompleteTextView)?.setAdapter(adapter)
        }
    }
and this in string values
Copy code
<string-array name="gender_array">
        <item>Female</item>
        <item>Male</item>
        <item>Non-binary/Third Gender</item>
        <item>Prefer not to say</item>
        <item>Other</item>
    </string-array>
let me know if it works for you...this is a dropdown spinner showing gender selection.