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?
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.
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.
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.
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.
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.
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? 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.
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.
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!
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