1

I am using the following line of code currently and it works fine. I have an array called somearray declared under strings.xml

ArrayAdapter<CharSequence> adapter_teh = ArrayAdapter.createFromResource(AttendActivity.this, R.array.somearray, android.R.layout.simple_spinner_item);

However, I now wish to use List<String> instead of R.array.somearray. Basically, I am now getting a List from an API call which needs to be populated to the adapter_teh instead of the hardcoded array in Strings.xml

2 Answers 2

1

You can use ArrayAdapter<String> and pass your List<String> to adapter constructor, try below code

ArrayAdapter<String> adapter_teh = new ArrayAdapter<String>(AttendActivity.this, android.R.layout.simple_spinner_item, yourArrayList);

Hope this help you and solve your problem.

Sign up to request clarification or add additional context in comments.

Comments

0

from resources

String[] yourStringArray = getResources().getStringArray(R.array.stringarray);

using String class

String[] yourStringArray = new String[]{"A1","A3","A4","A6","A7","A8"};

Common Adapter

ArrayAdapter<String> adapter = new ArrayAdapter<>(AttendActivity.this,android.R.layout.simple_list_item_1,android.R.id.text1,yourStringArray);

1 Comment

yes, edited, that should work, you just need to dynamically populate the string array now.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.