Reputation: 209
Generally AutoCompleteTextView
is populated with strings.xml
file in res/values
folder. Can anyone tell me how to use a string array created in the class to populate AutoCompleteTextView
?
Upvotes: 2
Views: 6390
Reputation: 111
Try it:
result_auto_txt.setAdapter(new ArrayAdapter<>(RegisterEmployeeActivity.this, android.R.layout.simple_list_item_1,getResources().getStringArray(R.array.result)));
This is very help for string.xml
to list using
array.
Upvotes: 0
Reputation: 73
I did it this way:
((AutoCompleteTextView) findViewById(R.id.autoCompleteTextView1)).setAdapter(
new ArrayAdapter<String> (this, android.R.layout.simple_dropdown_item_1line,
String_array));
where autoCompleteTextView1
is your Autocompletetextview field name String_array is the array you wanted to pass.
Upvotes: 0
Reputation: 1208
Try this...
autocompletetextAdapter = new ArrayAdapter<String>(
this,
android.R.layout.simple_dropdown_item_1line, stringArray);
myAutocompleteTextView.setAdapter(autocompletetextAdapter);
Upvotes: 14
Reputation: 1078
simply by creating a public method like: getArray () in the class where the array is obtained then you use it with your autocomplete textview
Upvotes: 0