【问题标题】:How to clear AutoCompleteTextView with inputType = none如何使用 inputType = none 清除 AutoCompleteTextView
【发布时间】:2021-03-24 22:02:41
【问题描述】:

我的 UI 中需要一个下拉菜单。按照我在material.io 上找到的说明,我将AutoCompleteTextView 与inputType="none" 一起使用。我需要在按下按钮时重置它并再次显示占位符,但如果我使用 setText("") 它将显示一个空选择,我想实际清除 AutoCompleteTextView 并再次显示占位符。我怎样才能完成它?

【问题讨论】:

    标签: android kotlin material-components-android


    【解决方案1】:

    试试这个

    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
            }
    

    【讨论】:

    • 成功了,谢谢!只是为了澄清,我不明白为什么这里需要 isFocusable = false 。你能解释一下吗?无论如何,该解决方案运行良好!
    猜你喜欢
    • 2012-04-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-01-02
    • 2018-04-07
    相关资源
    最近更新 更多