user1387035
user1387035

Reputation: 209

how to populate autocompletetextview with string array created in a class

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

Answers (4)

SHUBHAM SONI
SHUBHAM SONI

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

sugra
sugra

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

Mehul Santoki
Mehul Santoki

Reputation: 1208

Try this...

autocompletetextAdapter = new ArrayAdapter<String>(
                        this,
                        android.R.layout.simple_dropdown_item_1line, stringArray);

myAutocompleteTextView.setAdapter(autocompletetextAdapter);

Upvotes: 14

letroll
letroll

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

Related Questions