android fill singlechoiceitems dialog with arraylist values
android, java
Solution
Use ArrayList to build your items:
List<String> items = new ArrayList<String>();
items.add("this");
items.add("that");
Then convert it to an array when passing it to `setSingleChoiceItems`:
b.setSingleChoiceItems(items.toArray(new String[items.size()]), 0, new DialogInterface.OnClickListener() { ... });
If you wanted to implement a single datasource, you could implement the Cursor interface but that might be overkill for this.
Problem
I defined an array like, ``` String[] types = {"item0", "item1", "item2", "item3", "item4", "item5", "item6", "item7", "item8", "item9"}; ``` Once I fill it, I use its results to fill an alert dialog with single choice items, ``` AlertDialog.Builder b = new Builder(this); b.setTitle("Results"); b.setSingleChoiceItems(types, 0, new DialogInterface.OnClickListener() { ``` problem is that result size is variable and item list is filled always with fixed value. I would like to use an ArrayList but setSingleChoiceItems method doesn't accept it. How to reach it? Thank you