Issue
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.
Solution
We need to pass false
as second argument to setText() method.
autoCompleteTextView.setText("First", false);
If we don't pass second arguiment "false"
as a filter to setText()
method, it will clear all the entries inside list and will keep just one entry. that we set as using setText()
method.
Answered By - Owais Yosuf
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.