Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Are there any side-effects of using multiple string.xml files?

I am currently creating an application that have some strings (>300 for now) and I have some problems to quickly find a string with so many of them. So I was considering the possibility of using several string.xml files instead of only one (string_menu, string_activity1, ...).

Is there any side-effect with this practice? Is it a bad or a good practice?

I ask this because it seems that no many people on the net are using this possibility. So maybe there is some problem with it?

like image 913
sam Avatar asked Dec 17 '12 21:12

sam


People also ask

What is the advantage of making strings in strings xml file?

One of the main benefits is for localization: you keep your code language-independent and just need to provide a different XML file for each language you want to support.

Where is the strings xml file located?

Open any of your activity's xml file. Press Ctrl Key and move your mouse pointer to the text where it is indicating @string/loginTitle and click. This will open your string. xml file.

What is string resource 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. String Array.

What are the disadvantages of XML file format?

The redundancy in syntax of XML causes higher storage and transportation cost when the volume of data is large. 3. XML document is less readable compared to other text-based data transmission formats such as JSON. 4. XML doesn’t support array.

What is the role of string in XML?

Here we explained the basics of String and their role in XML which is quite beneficial in hierarchical data structures also done with real-time examples of how the strings are extracted from the schema file. They provide an ability to describe element type with a string like a string to be started from upper case / lower case or any other ranges.

What are the advantages of using XML?

The data stored and transported using XML can be changed at any point of time without affecting the data presentation.

How to initialize string in XML?

How to Initialize String in XML? A string is initialized in the Element name with the type ‘string’. For example: It returns the string in the element name, if it is an integer then it returns a value. If the type doesn’t have any content then it could be declared as a string, not as any data types.


2 Answers

As stated in the documentation you can use whatever filename you want:

The filename is arbitrary. The <string> element's name will be used as the resource ID.

like image 142
chrulri Avatar answered Oct 14 '22 16:10

chrulri


There may be negligible side effects in performance, you can add as much as you can. I have 3 activity files MainActivity, PhotoActivity, UserActivity, create a common strings.xml file and other activity related files.

-strings.xml                    -> create common string values here.   --strings_main.xml            -> create main activity specific string values here.   --strings_photo.xml           -> ...   --strings_user.xml            -> ... etc etc 

Hope this is helpful. Thanks!

like image 41
Madan Sapkota Avatar answered Oct 14 '22 15:10

Madan Sapkota