Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting value in AutoCompleteTextView

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?

like image 942
Jose Manuel Avatar asked Dec 05 '22 03:12

Jose Manuel


1 Answers

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

like image 173
Jared Burrows Avatar answered Jan 08 '23 21:01

Jared Burrows