Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/198.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 如何在inputType=none时清除AutoCompleteTextView_Android_Kotlin_Material Components Android - Fatal编程技术网

Android 如何在inputType=none时清除AutoCompleteTextView

Android 如何在inputType=none时清除AutoCompleteTextView,android,kotlin,material-components-android,Android,Kotlin,Material Components Android,我需要一个下拉菜单在我的用户界面。按照我在上找到的说明,我将AutoCompleteTextView与inputType=“none”一起使用。我需要在按下按钮时将其重置并再次显示占位符,但是如果我使用setText(“”),它将显示一个空选项,我希望实际清除AutoCompleteTextView并再次显示占位符。我怎样才能做到呢?试试这个 在java中: button.setOnClickListener(v->{ autoCompleteTextView.s

我需要一个下拉菜单在我的用户界面。按照我在上找到的说明,我将AutoCompleteTextView与
inputType=“none”
一起使用。我需要在按下按钮时将其重置并再次显示占位符,但是如果我使用
setText(“”
),它将显示一个空选项,我希望实际清除AutoCompleteTextView并再次显示占位符。我怎样才能做到呢?

试试这个

java中

 button.setOnClickListener(v->{
            autoCompleteTextView.setText(null);
            //autoCompleteTextView.setText("");// or you can use this
            autoCompleteTextView.setFocusable(false);
        });
button.setOnClickListener { v: View? ->
            autoCompleteTextView.setText(null)
            autoCompleteTextView.isFocusable = false
        }
这是给Kotlin的:

 button.setOnClickListener(v->{
            autoCompleteTextView.setText(null);
            //autoCompleteTextView.setText("");// or you can use this
            autoCompleteTextView.setFocusable(false);
        });
button.setOnClickListener { v: View? ->
            autoCompleteTextView.setText(null)
            autoCompleteTextView.isFocusable = false
        }

成功了,谢谢!我只是想澄清一下,我不明白为什么这里需要isFocusable=false。你能再解释一下吗?无论如何,这个解决方案是完美的!