I have an empty string-array resource in my strings.xml file like below:
<string-array name="categories"/>
I'm getting array of data from an API back which I need to populate onto a listview. Its ArrayAdapter takes in an @ArrayResource int for its resource like below:
public void showListViewDialog(…, @ArrayRes int arrayResource) {
...
ListView listView = alertDialogView.findViewById(R.id.listViewCategories);
ArrayAdapter arrayAdapter = ArrayAdapter.createFromResource(context,
arrayResource, R.layout.custom_list_item);
listView.setAdapter(arrayAdapter);
}
In my Java class, this is how I am retrieving the string-array resource:
List<String> categoriesToAdd= Arrays.asList(getResources().getStringArray(R.array.categories));
How can I then add the data back to it? I've tried the following but it does not work:
List<String> listCategories = new ArrayList<>();
listCategories.add(categoriesToAdd);