Are strings.xml string arrays always parsed / deserialized in the same order?

Can I count on string arrays in the strings.xml resource file to parse or deserialize in the same order every time ?

If anyone can refer to any documentation that clearly states this warranty, I would appreciate it. Or, at least, we offer significant experience with this topic.

Also, is this the best practice or am I missing a simpler solution?

Note. . This will be a short list, so I'm not going to implement a more complex database or custom XML solution, unless I need it.

<!--KEYS (ALWAYS CORRESPONDS TO LIST BELOW ??)--> <string-array name="keys"> <item>1</item> <item>2</item> <item>3</item> </string-array> <!--VALUES (ALWAYS CORRESPONDS TO LIST ABOVE ??)--> <string-array name="values"> <item>one</item> <item>two</item> <item>three</item> </string-array> 
+1
source share
1 answer

Yes, as far as I know, you can assume that the order of the elements will be the same every time, which means that you can safely define key / value pairs using separately declared xml arrays. Take a look at the API demos (e.g. arrays.xml ) and you will see that Google uses the same method to specify a static key / value pair. In particular, you can infer this from entries_list_preference and entryvalues_list_preference . In fact, if you think about it: it hardly makes sense to suggest the attributes entryValues and entryValues to point to static resources, for example. a ListPreference if their order is not guaranteed.

Addendum: multidimensional arrays are not supported in xml. However, you can write your own XML parser to handle these cases, which is actually not as difficult as it might seem. You will probably need more time than just defining two one-dimensional arrays.

+4
source

Source: https://habr.com/ru/post/969698/


All Articles