android - 如何使用 inputType = none 清除 AutoCompleteTextView
问题描述
我的 UI 中需要一个下拉菜单。按照我在material.io上找到的说明,我将 AutoCompleteTextView 与inputType="none"
. 我需要在按下按钮时重置它并再次显示占位符,但如果我使用setText("")
它会显示一个空的选择,我想真正清除 AutoCompleteTextView 并再次显示占位符。我怎样才能实现它?
解决方案
试试这个
在java中:
button.setOnClickListener(v->{
autoCompleteTextView.setText(null);
//autoCompleteTextView.setText("");// or you can use this
autoCompleteTextView.setFocusable(false);
});
这对于Kotlin来说:
button.setOnClickListener { v: View? ->
autoCompleteTextView.setText(null)
autoCompleteTextView.isFocusable = false
}
推荐阅读
- mysql - 如何检查一列是否有两个以上的项目,以及它是否比 SQL 中的 avg() 多?
- themes - 如何更改 RStudio 终端中光标的颜色?
- php - 使用 PHP 的 API PUT 请求
- c++ - 本地对象超出范围后异步成员函数会发生什么?
- flutter - 流生成器不接收数据(无限连接状态 = 等待)颤振
- flask - 有没有办法为模板中的 Flask WTForms 错误简化此代码
- python - python3中key=len, key=lambda x: (len(x), x)) 有什么区别
- python-sphinx - 仅在页面右侧三分之一处带有 Sphinx 和 RinohType 的代码文档
- c++ - 无法从项目目录打开 .txt 文件
- sql - 反透视取自另一个表的列