Reputation: 807
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?
Upvotes: 7
Views: 20413
Reputation: 369
You can set the default value of AutoCompleteTextView using following ways:
Using position or index
myAutoCompleteTextView.setText(adapter.getItem(1),false);
Using the value or string
myAutoCompleteTextView.setText(value,false);
If you want to do the filter also, then remove the false.
myAutoCompleteTextView.setText(value);
Upvotes: 3
Reputation: 145
setText(CharSequence text, boolean filter)
if you don't want filter. You can make it false
:
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
myAutoCompleteTextView.setText(adapter.getItem(2),false);
}
Upvotes: 8
Reputation: 55517
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
Upvotes: 15