Android AlertDialog隐藏AutoCompleteTextView下拉列表

Android AlertDialog隐藏AutoCompleteTextView下拉列表,android,kotlin,android-alertdialog,autocompletetextview,Android,Kotlin,Android Alertdialog,Autocompletetextview,在我的表单中,有两个由自定义适配器填充的AutoCompleteTextView。但是搜索需要一两秒钟,所以我想在AlertDialog中向用户显示正在加载的动画。 为了实现这一点,我在SearchAdapter中声明了一个BooleanLiveData变量,并在活动中观察它。 我的目标是,当观察到的变量为真时显示AlertDialog,当变量为假时取消。因此,这是非常困难的 下面是显示对话框的代码段 // To simplfy question I am using standart Aler

在我的表单中,有两个由自定义适配器填充的AutoCompleteTextView。但是搜索需要一两秒钟,所以我想在AlertDialog中向用户显示正在加载的动画。 为了实现这一点,我在SearchAdapter中声明了一个BooleanLiveData变量,并在活动中观察它。 我的目标是,当观察到的变量为真时显示AlertDialog,当变量为假时取消。因此,这是非常困难的

下面是显示对话框的代码段

// To simplfy question I am using standart AlertDialog, the same problem occurs here,too
        val builder: AlertDialog.Builder? = AlertDialog.Builder(this, R.style.AlertDialogCustom)
        }
        builder?.setMessage("Results are loading")
                ?.setTitle("Loading")
        val dialog: AlertDialog? = builder?.create()

        SearchAdapter.isFetching.observe(this, Observer<Boolean> { isFetching ->
            isFetching?.let {
                if (it) {
                    dialog?.show()
                } else {
                    dialog?.hide()
                }
            }})
<style name="AlertDialogCustom" parent="Theme.MaterialComponents.Dialog.Alert">
        <item name="android:colorAccent">@color/white</item>
    </style>