0

I am trying to take an of strings and is dynamically created at runtime, and populate a spinner with them.

Is this possible, I can not find an approach to do this with in the documentation.

1 Answer 1

1

Yes, it can be done

ArrayAdapter<String> spinnerArrayAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, spinnerArray);
spinnerArrayAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinner.setAdapter(spinnerArrayAdapter);

and when the data got changed, repeat the same flow above and it'll refresh the Spinner.

A more clean solution is to create the adapter once and call mAdapter.notifyDatsetChanged() when the list gets updated. The same approach like when you're using a ListView or RecyclerView.

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

Comments

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.