i have an android application which use a gallery aspect of choose a symbol and assign it to some button. The icon set is situated in res/drawable folder and it is utilized within the gallery using the typical adapter from the guide: private Integer[] Imgid = After a symbol selecting, i saved the configurations inside a db with id from the button as well as the drawable. All works done, but i have observed when i'll wish to add or modify my icon set or assets generally of my application, ids of old resource could change, therefore the preferences within the db describes wrong icon. It is possible to method to pressure that old id of R class so that they did not change later on? Or perhaps is there a different way to manage the product from the component galley with another attribute than id? (maybe string title and reflection?)

thanks ahead of time

You shouldn’t depend around the actual values from the R.drawable.* characteristics.
Make your own ids rather (for instance 1 match R.drawable.icon_home and a pair of match R.drawable.icon_home2)

String title and reflection should work too, but it’s most likely just a little overkill you've merely a couple of symbols.

You cannot use static int for resource identifier, however you should think about two techniques od Resources class:



You are able to keep title from the drawable within the database if you do not intend to change that. getResourceEntryName returns the title in the resource id:

Resources resources = getResources();
String name = resources.getResourceEntryName(R.drawable.icon);

And you will return the resource id in the title with getIdentifier:

int resId = resources.getIdentifier(name, "drawable", "your.package.name");