I am having trouble setting a default value on my AutoCompleteTextView. First, I tried doing setText("default value")
. Then, I searched and tried this:
autoText.postDelayed(new Runnable() {
@Override
public void run() {
autoText.showDropDown();
}
},500);
autoText.setText("chi");
autoText.setSelection(tvNewRestoAddress.getText().length());
but it still doesn't work. Any suggestions?
Try this
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);
String[] fruits = {"Apple", "Banana", "Cherry", "Date", "Grape", "Kiwi", "Mango", "Pear"};
ArrayAdapter<String> adapter = new ArrayAdapter<String>
(this, android.R.layout.select_dialog_item, fruits);
AutoCompleteTextView actv = (AutoCompleteTextView) findViewById(R.id.autoCompleteTextView);
actv.setThreshold(1);//will start working from first character
actv.setAdapter(adapter);//setting the adapter data into the AutoCompleteTextView
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.