MaterialAutoCompleteTextView automatically shows dropdown when changing theme

I’m using MaterialAutoCompleteTextView to display a dropdown list for selecting a theme.
xml:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code><com.google.android.material.textfield.TextInputLayout
android:id="@+id/chooseThemeContainer"
style="@style/ChooseThemeInputLayout"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:layout_marginEnd="16dp"
android:hint="@string/theme"
android:textColorHint="@color/textLink"
app:endIconTint="@color/textLink"
app:layout_constraintEnd_toStartOf="@id/saveName"
app:layout_constraintStart_toStartOf="@id/avatar"
app:layout_constraintTop_toBottomOf="@id/avatar">
<com.google.android.material.textfield.MaterialAutoCompleteTextView
android:id="@+id/chooseTheme"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:drawableTint="@color/textLink"
android:inputType="none"
android:textColorHint="@color/textLink"
android:textColor="@color/textLink"/>
</com.google.android.material.textfield.TextInputLayout>
</code>
<code><com.google.android.material.textfield.TextInputLayout android:id="@+id/chooseThemeContainer" style="@style/ChooseThemeInputLayout" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_marginTop="8dp" android:layout_marginEnd="16dp" android:hint="@string/theme" android:textColorHint="@color/textLink" app:endIconTint="@color/textLink" app:layout_constraintEnd_toStartOf="@id/saveName" app:layout_constraintStart_toStartOf="@id/avatar" app:layout_constraintTop_toBottomOf="@id/avatar"> <com.google.android.material.textfield.MaterialAutoCompleteTextView android:id="@+id/chooseTheme" android:layout_width="match_parent" android:layout_height="match_parent" android:drawableTint="@color/textLink" android:inputType="none" android:textColorHint="@color/textLink" android:textColor="@color/textLink"/> </com.google.android.material.textfield.TextInputLayout> </code>
<com.google.android.material.textfield.TextInputLayout
        android:id="@+id/chooseThemeContainer"
        style="@style/ChooseThemeInputLayout"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_marginTop="8dp"
        android:layout_marginEnd="16dp"
        android:hint="@string/theme"
        android:textColorHint="@color/textLink"
        app:endIconTint="@color/textLink"
        app:layout_constraintEnd_toStartOf="@id/saveName"
        app:layout_constraintStart_toStartOf="@id/avatar"
        app:layout_constraintTop_toBottomOf="@id/avatar">

        <com.google.android.material.textfield.MaterialAutoCompleteTextView
            android:id="@+id/chooseTheme"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:drawableTint="@color/textLink"
            android:inputType="none"
            android:textColorHint="@color/textLink"
            android:textColor="@color/textLink"/>

    </com.google.android.material.textfield.TextInputLayout>

in the fragment’s onViewCreated method call initChangeThemeEditText():

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>private fun initChangeThemeEditText() {
viewModel.themeItems.observe(viewLifecycleOwner) { items ->
binding.chooseTheme.setSimpleItems(items)
val selectedIndex = when (themeController.themeType) {
ThemeController.ThemeType.AS_SYSTEM -> 0
ThemeController.ThemeType.DAY -> 1
ThemeController.ThemeType.NIGHT -> 2
}
binding.chooseTheme.setText(items[selectedIndex], false)
}
}
</code>
<code>private fun initChangeThemeEditText() { viewModel.themeItems.observe(viewLifecycleOwner) { items -> binding.chooseTheme.setSimpleItems(items) val selectedIndex = when (themeController.themeType) { ThemeController.ThemeType.AS_SYSTEM -> 0 ThemeController.ThemeType.DAY -> 1 ThemeController.ThemeType.NIGHT -> 2 } binding.chooseTheme.setText(items[selectedIndex], false) } } </code>
private fun initChangeThemeEditText() {
        viewModel.themeItems.observe(viewLifecycleOwner) { items ->
            binding.chooseTheme.setSimpleItems(items)

            val selectedIndex = when (themeController.themeType) {
                ThemeController.ThemeType.AS_SYSTEM -> 0
                ThemeController.ThemeType.DAY -> 1
                ThemeController.ThemeType.NIGHT -> 2
            }

            binding.chooseTheme.setText(items[selectedIndex], false)
        }
    }

themeController reads and writes the value of the installed theme to the database through the repository

from viewModel I get a list of strings:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>private val _themeItems = MutableLiveData<Array<String>>()
val themeItems: LiveData<Array<String>> = _themeItems
init {
val items = arrayOf(
resourceProvider.getString(stringResources.theme_as_system),
resourceProvider.getString(stringResources.theme_day),
resourceProvider.getString(stringResources.theme_night)
)
_themeItems.value = items
}
</code>
<code>private val _themeItems = MutableLiveData<Array<String>>() val themeItems: LiveData<Array<String>> = _themeItems init { val items = arrayOf( resourceProvider.getString(stringResources.theme_as_system), resourceProvider.getString(stringResources.theme_day), resourceProvider.getString(stringResources.theme_night) ) _themeItems.value = items } </code>
private val _themeItems = MutableLiveData<Array<String>>()
    val themeItems: LiveData<Array<String>> = _themeItems

    init {
        val items = arrayOf(
            resourceProvider.getString(stringResources.theme_as_system),
            resourceProvider.getString(stringResources.theme_day),
            resourceProvider.getString(stringResources.theme_night)
        )
        _themeItems.value = items
    }

On initial boot everything goes well. The saved value is correctly set to MaterialAutoCompleteTextView.
Next, in the selection listener, the theme changes if necessary.
And, it turns out, the fragment and its views are recreated.
And MaterialAutoCompleteTextView is displayed with the list open.

Setting binding.chooseTheme.dismissDropDown() after setText() had no effect.

I tried all the solutions from here.

The only thing that works is:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>...
binding.chooseTheme.setText(items[selectedIndex], false)
binding.chooseTheme.postDelayed(50) {
binding.chooseTheme.dismissDropDown()
}
</code>
<code>... binding.chooseTheme.setText(items[selectedIndex], false) binding.chooseTheme.postDelayed(50) { binding.chooseTheme.dismissDropDown() } </code>
...
binding.chooseTheme.setText(items[selectedIndex], false)
            binding.chooseTheme.postDelayed(50) {
                binding.chooseTheme.dismissDropDown()
            }

But this solution does not make me happy and is visible on the user interface.
Is there a normal way to force MaterialAutoCompleteTextView not to open the list after being recreated?

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật