I have an android application that needs to display strings found under the resources, but there can be multiple strings.xml
files, i.e. strings1.xml
, strings2.xml
and so third. The string key can reside in different stringsN.xml
files, now if a key is found in lets say strings1.xml
it should be displayed without looking into the other string files with the same key.
Is it possible in android? I have done this thing in my .Net application but seems not doable in android. Infact, android gives the compilation error when I enter values against duplicate keys in multiple strings.xml files.
EDIT
The reason for doing this is, there are different clients running my application. Lets assume for clientA I added the key "company" with the value "ABC" and in my default strings.xml file there is already a default company name with the same key "company" but with the defualt value "Default Company". Now, if clientA opens my application the company name should be "ABC" and "Default Company" for clients otherthan clientA.
It allows you to easily locate text in your app and later have it translated. Strings can be internationalized easily, allowing your application to support multiple languages with a single application package file (APK).
A string resource provides text strings for your application with optional text styling and formatting. There are three types of resources that can provide your application with strings: String. XML resource that provides a single string.
String. xml file contains all the strings which will be used frequently in Android project. String. xml file present in the values folder which is sub folder of res folder in project structure.In Android Studio, we have many Views such as TextView,Button,EditText,CheckBox,RadioButton etc.
No, this is not possible on Android.
You can only have duplicate resource names in different folders (values-qualifier
). Even then, the strings aren't duplicated. They are prepared for localization, and only one will be loaded at a time.
If you told us why you needed this, we could perhaps suggest a better solution.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With