I want to find out the integer value associated to a string into the R.string file, from the TextView control that displays it.
So, I have a TextView called MyTextView and I associated it’s string as this
MyTextView.setText(R.string.MyString);
Now, what I want is to create some function that gives me the string ID of MyTextView, something like GetStringId(MyTextView). Maybe the TextView package already has this implemented and I cannot find it.
Thanks for your help
To add multiple translations to your application, you should use the “language-qualified-resources”, as explained on the Android Docs.
Basically, you add your strings for the fallback-language (which is often English), to your
res/values/strings.xml-file.Any other translations (e.g. for Spanish) go into their language-qualified-resource directory with the given language-qualifier (specified in ISO 639-1). For Spanish, this would be
res/values-es/strings.xml.Android then checks the current device-language, searches for any translations with the corresponding language-qualifier, and automatically uses the strings specified in that file. If it can’t find any folder with a corresponding language-qualifier, it uses the one without a qualifier (e.g. the “fallback”-language).
This is a service from Android, you simply have to put the corresponding translations in the corresponding language-qualified folders and Android will do the rest for you.
Also see this older question: internationalisation in android