Adam
Adam

Reputation: 2202

How to make a spinner from string?

I have this problem. I read with BufferedReader text from one system file, this text contains for example 5 WORDS, but in another case it can contain less or more words, then I put this text (these words) to ONE string and save that string to shared preferences.

And my question is that how can I make a spinner from this string?

I have seen it's possible.

Upvotes: 0

Views: 252

Answers (1)

hwrdprkns
hwrdprkns

Reputation: 7585

I'm not really sure what your preferences string looks like, but assuming that the words are separated with a ",".

Spinner spinner = new Spinner(this);
    ArrayAdapter<String> spinnerArrayAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_dropdown_item, yourString.split(","));
    spinner.setAdapter(spinnerArrayAdapter);

Upvotes: 2

Related Questions