【发布时间】:2021-10-02 17:50:29
【问题描述】:
我*有一个简单的“材质微调器”实现:
<com.google.android.material.textfield.TextInputLayout
style="@style/Widget.MaterialComponents.TextInputLayout.FilledBox.ExposedDropdownMenu"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<AutoCompleteTextView
android:id="@+id/filled_exposed_dropdown"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="none"/>
</com.google.android.material.textfield.TextInputLayout>
以及填充列表的我的片段 onCreate 方法
AutoCompleteTextView editTextFilledExposedDropdown;
ArrayAdapter<String> adapter = null;
@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
String[] type = new String[] {"Bed-sitter", "Single", "1- Bedroom", "2- Bedroom","3- Bedroom"};
adapter =new ArrayAdapter<>( getContext(),R.layout.dropdown_menu_popup_item, type);
editTextFilledExposedDropdown = view.findViewById(R.id.filled_exposed_dropdown);
editTextFilledExposedDropdown.setAdapter(adapter);
}
只要我不选择项目并旋转手机,代码就可以正常工作。
一旦我旋转手机,onCreate 方法就会再次被调用,但由于某种原因,唯一可用的项目是我之前选择的项目。
菜单不显示所有其他项目。
原因可能是什么? 我故意重新填充 arrayadapter,以确保在旋转手机时使用相同的对象。
【问题讨论】:
-
尝试设置
editTextFilledExposedDropdown.setFreezesText(false); -
@Zain unfourtantly that didn't work :/.
标签: android spinner android-spinner oncreate android-textinputlayout