I do have a lot of language specific resources. There's one point in my Android apps where I do get a resource value and need to translate this value into the matching id. The value is not neccessarily in the language specific file for the current language (en/de/...). It's somewhere in there ... and it's unique.
After reading the docs and this thread "http://stackoverflow.com/questions/3476430/get-resource-id-by-passing-name-as-a-parameter-in-android" I thought that "getIdentifier(String name, String defType, String defPackage)" is the correct way to go but I can't get it to work. The result is always "0".
This code is part of an activity and I'm on Android 2.2.
Is it possible that Android doesn't take all resource files into account and searches just in the current language specific one?
For an example (current language is "de"):
File: values-en/strings.xml
<resources>
<string name="txt_afirsttext">A first text</string>
<string name="txt_asecondtext">A second text</string>
</resources>
File: values-de/strings.xml
<resources>
<string name="txt_afirsttext">Ein erster Text</string>
<string name="txt_asecondtext">Ein zweiter Text</string>
</resources>
// Now I want to find the ID to this "en" text ...
String testValue = "A second text";
int i = this.getResources().getIdentifier(testValue, "strings", this.getPackageName());
// ... and translate it to the actual "de" language
String translatedValue = this.getResources().getString(i);
To make things clear. I don't want to mis-use string resources as a database. It's only one part that occurs on very rare situations.
Many thanks in advance. HJW