I have made various string-arrays in the string.xml file and I have to set different arrays as entries for the spinner according to certain condition in Java. Is it possible or is database the only way to do so. Thanks in advance.
Example to demonstrate the SpinnerUse ArrayAdapter to store the courses list. Create a single MainActivity that contains the spinner and on clicking any item of spinner Toast with that course name will be shown. Creating the activities: There will be one activity and hence one XML file for MainActivity. activity_main.
You need to use an adapter and populate with tha array in xml file.
Specify the name of your array in xml at createFromResource method (second parameter).
ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this, R.array.my_array, android.R.layout.simple_spinner_item);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
mySpinner.setAdapter(adapter);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With