Alain wrote:
> Instead of accessing items in a string array directly
>        items = getResources().getStringArray(R.array.name);
> 
> Can a variable be used in getString array as shown below
> 
> String itemName = "name";
> String getRes = "R.array."+ itemName;
> items = getResources().getStringArray(getRes);

Curiously, I just answered a related question seconds ago on StackOverflow:

http://stackoverflow.com/questions/2349652/android-open-resource-from-drawable-string/2349758#2349758

Given itemName, you can get the integer resource ID via the
getIdentifier() method on the Resources object.

This uses reflection, apparently, and therefore is comparatively
expensive. Avoid it if possible, cache it if you need to use it.

-- 
Mark Murphy (a Commons Guy)
http://commonsware.com | http://twitter.com/commonsguy

Android App Developer Books: http://commonsware.com/books

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to