The following SO question how-can-i-assign-an-id-to-a-view-programmatically explains how to set id to views programmatically .My problem is slightly different. I would want to know if it is possible to set resource id/name to arrays programmatically.
ArrayList<String> new_list = new ArrayList<>();
String [] stringArray = {"foo", "bar"};
for(String str:stringArray) {
new_list.add(str);
}
/* This is a random example of doing things I
* certainly have more complex computation
* add more random item and convert it back to array
*/
new_list.add("random_1");
new_list.add("random_n");
String [] updatedArray = new String[new_list.size()];
updatedArray = new_list.toArray(updatedArray);
Resource ID is defined like
<?xml version="1.0" encoding="utf-8"?>
<resources>
<item name="reservedNamedId" type="id"/>
</resources>
Now I want to do something like this
updatedArray.setID(R.id.reservedNamedId);
But that does not compile since array does not have a method setID like the Views class.
I understand if my string-array is defined in xml, I could use the name attribute to access it globally but what what I want is to programmatically create an array and assign a global name/id. So the basic intention was to define an array resource and make it available globally through resource id. Is it possible? Is it achievable in some other way?