Christian Bringino
Christian Bringino

Reputation: 155

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?

Upvotes: 3

Views: 8731

Answers (3)

Mubarrat Hasan
Mubarrat Hasan

Reputation: 304

Trying to add property on XML like -

<AutoCompleteTextView
    ...

    android:text="Here your text" />

or in java

autocompletetextview.setText("Here your text");

Upvotes: 0

Goku
Goku

Reputation: 9692

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);

Upvotes: 4

Pratik18
Pratik18

Reputation: 375

 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

Upvotes: 0

Related Questions