我在为 AutoCompleteTextView 设置默认值时遇到问题。
首先,我尝试执行 setText("default value")
。
然后,我搜索并尝试了这个:
autoText.postDelayed(new Runnable() {
@Override
public void run() {
autoText.showDropDown();
}
},500);
autoText.setText("chi");
autoText.setSelection(tvNewRestoAddress.getText().length());
但是还是不行。有什么建议吗?
最佳答案
试试这个
AutoCompleteTextView autoCompleteTextView = (AutoCompleteTextView) findViewById(R.id.edt);
String[] array = {"abc", "bcd", "cde", "def", "efg", "fgh", "PREM"};
ArrayAdapter<String> adapter = new ArrayAdapter<String>
(this, android.R.layout.select_dialog_item, array);
autoCompleteTextView.setAdapter(adapter);
autoCompleteTextView.postDelayed(new Runnable() {
@Override
public void run() {
autoCompleteTextView.setText("PREM");
autoCompleteTextView.showDropDown();
}
}, 10);
关于java - 如何在 AutoCompleteTextView 上设置文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47450935/