Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multiple string resource files with similar keys in Android

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.

like image 431
Ibad Baig Avatar asked Apr 10 '13 13:04

Ibad Baig


People also ask

Why should you use string resources instead of hard coded strings in your apps?

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).

What are string resources in Android?

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.

What is strings XML?

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.


1 Answers

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.

like image 62
Raghav Sood Avatar answered Oct 07 '22 20:10

Raghav Sood