android - AlertDialog 隐藏 AutoCompleteTextView 下拉菜单
问题描述
在我的表单中,有两个由自定义适配器填充的 AutoCompleteTextView。但是搜索需要一两秒钟,所以我想在 AlertDialog 中向用户显示加载动画。为了实现这一点,我在搜索适配器中声明了一个布尔 LiveData 变量,并在活动中观察它。我的目标是,当观察到的变量为真时显示 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()
}
}})
问题是当dialog?.show()
名为 AutoCompleteTextView 的建议列表的代码不可见时。如果我评论该行,除了 AlertDialog (因为我评论了show()
命令)之外,一切都可以正常工作。
我捕获了两个视频,首先dialog?.show()
评论了一行并且 AutoCompleteTextView 工作正常
在第二dialog?.show()
行没有评论,AutoCompleteTextView 没有按预期工作。
我无法弄清楚 AutoCompleteTextView 的下拉菜单和 AlertDialog 之间有什么问题,希望您能帮助我找出答案。
额外:AlertDialogCustom 样式仅用于将 TextColor 更改为白色以在由主题强制的黑色背景上显示消息。
<style name="AlertDialogCustom" parent="Theme.MaterialComponents.Dialog.Alert">
<item name="android:colorAccent">@color/white</item>
</style>
解决方案
推荐阅读
- python - 我得到 TypeError: 'NoneType' object is not iterable, 尝试过滤列表时
- javascript - 如何在 JavaScript 中添加动态创建的脚本标签属性?
- c++ - unsigned long long int 在循环中的奇怪行为
- r - 如果使用 updateselectInput() 会快速刷新 DT
- java - 在 IntelliJ 上生成 JAR
- asp.net-mvc - Control + F5 对某些图像随机给出 403 禁止错误
- azure-active-directory - 是否有 Graph API 可以通过 AD B2C 获取所有登录活动?
- xml - 在一行中使用 DFDL 解析输入
- jenkins - SecureGroovyScript.script 期望类 java.lang.String 但收到 SecureGroovyScript
- python-3.x - 随机森林算法中随机状态参数的重要性是什么?