'How to set text on AutoCompleteTextView
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?
Solution 1:[1]
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
Solution 2:[2]
Trying to add property on XML like -
<AutoCompleteTextView
...
android:text="Here your text" />
or in java
autocompletetextview.setText("Here your text");
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Pratik18 |
| Solution 2 |
