Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting the value of the spinner dynamically

I have an ArrayAdapter as follows

ArrayAdapter<String>dataAdapter = new ArrayAdapter<String>(this,android.R.layout.simple_spinner_dropdown_item);

This is the adapter which I am going to use for my Spinner.I have value sets (String array) for the Spinner in my strings.xml file.

How can I set the <string-array> in string.xml to the spinner pragmatically? Please help!

like image 281
PeakGen Avatar asked Dec 08 '22 18:12

PeakGen


1 Answers

Just add it to your ArrayAdapter when you create it.

String[] yourArray = getResources().getStringArray(R.array.array_name);

ArrayAdapter<String>dataAdapter = new ArrayAdapter<String>(this,android.R.layout.simple_spinner_dropdown_item, yourArray);
like image 104
Slickelito Avatar answered Dec 11 '22 10:12

Slickelito