I have this simple layout for ExposedDropdownMenu
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/outlinedTextField3"
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox.Dense.ExposedDropdownMenu"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_marginStart="8dp"
android:hint="Gender">
<AutoCompleteTextView
android:id="@+id/genderText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:simpleItems="@array/customer_gender"
android:inputType="none"
android:text="female"
/>
</com.google.android.material.textfield.TextInputLayout>
If I don't set android:text="female"
I can select items from customer_gender
. However, I want to fill the form with Data Binding. It was simple setup.
Now, even if I'm using binding.genderText.setText("a gender")
, I'm getting the same result. The list doesn't show the other elements.
If we enable editing on the menu then after erasing the set initial value, we can see the menu items. It seems like the setting the text
overrides the menu list.
- How can I set the initial value?
Note: If I've used binding.genderText.setText("female", false)
then everything works fine. Still, I cannot set in the XML as intended. I guess the false
option is not available in the XML.