Android: Get String From Resource By Name
November 29th, 2009
No comments
Usually the string resources in your Android application are being referred to by a unique ID. But sometimes you will want to recover a string by its key, e. g. when you build the key of the string at the run time of your application (“Battery_Health_2″ or “Battery_Health_3″). You can do that like this:
private String getStringResourceByName(String aString) { String packageName = "com.coliena.myapp"; int resId = getResources().getIdentifier(aString, "string", packageName); return getString(resId); }
Check this link if you need to recover in image resource by its name.
More information about string resources is available in the Android Developer Documentation.