Setting value in AutoCompleteTextView

Issue

I have a AutoCompleteTextView with a list of items, and I need select one of them…

I am doing something like:

myAutoCompleteTextView.setListSelection( index);

and…

myAutoCompleteTextView.setText( index);

but don’t work… How can I set a item by default?

Solution

This will not work because setText takes a CharSequence.

myAutoCompleteTextView.setText(index);

public final void setText (CharSequence text)

Source: http://developer.android.com/reference/android/widget/TextView.html#setText(java.lang.CharSequence)

If you have a data structure such as a List<String> data, you can do something like this:

myAutoCompleteTextView.setText(data.get(index));

Source: http://developer.android.com/reference/android/widget/AutoCompleteTextView.html

Answered By – Jared Burrows

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published