I am trying to populate Spinner values โโof some Strings string.xml . I am trying to do this:
final List<String> list = new ArrayList<String>(); for (int i = 0; i < 86; i++) { String resource = "R.string." + ntpServers[i][0]; list.add(getResources().getString(resource)); }
I have lines similar to the following.
<string name="AT">Austria</string> <string name="BY">Belarus</string> <string name="BE">Belgium</string>
And from the geocoder I get a country code, such as AT, BY, etc., which are stored in the ntpServers array. I want to fill the counter with the name stored in the corresponding line, but I cannot do getResources().getString(resource) , because resource is String not a int .
How can i solve this?
Thanks for your advice.
PD :.
I get the following sequence:
Example:
geocoder.getCountry() = ES --> ntpServers[36][0] = ES --> R.string.ES = """Spain"""
What is the line I want in spinner.
____________________________
This is what I'm trying to do now. I am using getIdentifier .
final List<String> list = new ArrayList<String>(); for (int i = 0; i < 86; i++) { String resource = "R.string." + ntpServers[i][0]; Log.i("RESOURCE", resource); Log.i("getResource", "" + getResources().getIdentifier(resource, "string", getPackageName())); list.add(getResources().getString(getResources().getIdentifier(resource, "string", getPackageName()))); }
And this is a cat log
09-18 19:32:43.815: I/RESOURCE(31268): R.string.Global 09-18 19:32:43.815: I/getResource(31268): 0 09-18 19:32:43.815: W/ResourceType(31268): No package identifier when getting value for resource number 0x00000000 09-18 19:32:43.815: D/AndroidRuntime(31268): Shutting down VM 09-18 19:32:43.815: W/dalvikvm(31268): threadid=1: thread exiting with uncaught exception (group=0x40fa92a0) 09-18 19:32:43.815: E/AndroidRuntime(31268): FATAL EXCEPTION: main 09-18 19:32:43.815: E/AndroidRuntime(31268): android.content.res.Resources$NotFoundException: String resource ID
And this is R.java:
public static final class string { public static final int AE=0x7f080049; public static final int AO=0x7f08005b; ... public static final int Global=0x7f080008;
Let's see if you can find out more.
Thank you forever ^^