AutoCompleteTextView autoCompleteTextView
ArrayAdapter<String> adapter;
ArrayList<String> list = new ArrayList<>();
@Override
protected void onCreate(Bundle savedInstanceState) {
// code...
list.add("First");
list.add("Second");
list.add("Third");
list.add("Forth");
list.add("Fifth");
autoCompleteTextView = findViewById(R.id.auto_complete);
adapter = new ArrayAdapter<>(this, R.layout.drop_down, list);
autoCompleteTextView.setAdapter(adpater);
}
then, after adding some strings to
ArrayList and linking that list with autoCompleteTextView using Adapter.
autoCompleteTextView.setSelection(3);
Now I want any of my item getting selected automatically, once I open this activity. I treid setSelection() method, but it is not working.
2
Answers
We need to pass
false
as second argument to setText() method.If we don't pass second arguiment
"false"
as a filter tosetText()
method, it will clear all the entries inside list and will keep just one entry. that we set as usingsetText()
method.your selected value will store selectedItem