是" strings.xml中"字符串数组总是解析/以相同的顺序反序列化? [英] Are "strings.xml" string arrays always parsed/deserialized in the same order?

查看:135
本文介绍了是" strings.xml中"字符串数组总是解析/以相同的顺序反序列化?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我能指望字符串数组的的strings.xml资源文件中被解析/反序列化在同一顺序的每次

如果任何人都可以列举,明确阐述了这一保证的任何文件,我AP preciate它。或者,最起码,提供的经验显著量与这个话题。

此外,这是一个最好的做法还是我失去了一个简单的解决方案?

注意:这将是一个小单子,所以我不希望实施更复杂的数据库或XML定制解决方案,除非我绝对有

 <! - 键(总是对应的文章?) -  GT;
<字符串数组名=键>
    <项目> 1 LT; /项目>
    <项目> 2'; /项目>
    <项目>第3版; /项目>
< /字符串数组><! - VALUES(总是与上面所列内容??) - GT;
<字符串数组名=值>
    <项目>吲; /项目>
    <项目>二< /项目>
    <项目>三< /项目>
< /字符串数组>


解决方案

是的,据我所知,你可以假设项的顺序将是相同的每一次,这意味着你可以安全地定义键/值对使用单独的XML声明的数组。看一看的API演示(如 arrays.xml 文件),你会看到谷歌使用相同methodoly指定静态键/值对。更具体地讲,你就可以从 entries_list_ preference 演绎这和 entryvalues​​_list_ preference 。其实,如果你仔细想想:这很难成为有意义的报价 entryValues​​ 属性指向静态资源对于如一个目录preference 如果他们的秩序将无法得到保障。

附录:在XML多维数组不被支持。但是,您可以编写自己的XML解析器来处理这些案件,这其实并不难,因为它可能声音。这可能会花费你更多的时间虽然比简单地定义两个一维数组。

Can I count on string arrays within the "strings.xml" resource file to be parsed/deserialized in the same order every time?

If anyone can cite any documentation that clearly spells out this guarantee, I'd appreciate it. Or, at the very least, offer a significant amount of experience with this topic.

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

Note: This will be a small list, so I'm not looking to implement a more complicated database or custom XML solution unless I absolutely have to.

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

解决方案

Yes, as far as I'm aware you can assume that the order of items will be the same each time, meaning you can safely define key/value pairs using separately xml-declared arrays. Have a look at the API demos (e.g. the arrays.xml file) and you'll see that Google uses the same methodoly to specify static key/value pairs. More specifically, you'll be able to deduce this from entries_list_preference and entryvalues_list_preference. Actually, if you think about it: it would hardly make sense to offer entries and entryValues attributes for pointing to static resources for e.g. a ListPreference if their order wouldn't be guaranteed.

Addendum: Multi-dimensional arrays in xml are not supported. You can however write your own xml parser to handle those cases, which actually isn't as hard as it may sound. It would probably take you more time though than simply defining two one-dimensional arrays.

这篇关于是&QUOT; strings.xml中&QUOT;字符串数组总是解析/以相同的顺序反序列化?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆