如何访问字符串数组列表的XML结构如下 [英] How Access the String array list xml following structure

查看:148
本文介绍了如何访问字符串数组列表的XML结构如下的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已创建以下结构。这里水平达到4和团体均达到6相同的XML文件structure.But我无法访问为1级 - > group1->第一项,这也给项目。在这里,总体水平有4个,每个级别都有6个人组,每个组有10个不同的物品。

I have create following structure. Here levels are up to 4 and groups are up to 6 same xml file structure.But i cannot access as level1 -> group1-> first item, which has also to item. Here total level has 4 and each level has 6 individual group and each individual group has 10 individual items.

 <resources>
     <string-array name="level1">       

       <item>
            <string-array name="group1"> 
            <item>
                 <string-array>
                    <item>the</item>
                    <item>the little boy</item>         
                 </string-array>
            </item>        
            <item>
                 <string-array>
                    <item>a</item>
                    <item>a good boy</item>         
                  </string-array>
            </item>
        </string-array>
      </item>   

      <item>
        <string-array name="group2"> 
             <item>
                <string-array>
                   <item>he</item>
                   <item>he is it</item>            
                </string-array>
             </item>           
             <item>
                <string-array>
                     <item>i</item>
                      <item>i can go</item>         
                  </string-array>
                       ...
              </item>
               ...  
       </string-array>
             ...
   </item>  
...
</string-array>

下面一些code,我试试......

Here some code, that i try....

        final String  levels []=getResources().getStringArray(R.array.level);
        final TextView tw=(TextView)findViewById(R.id.txtWord);
         String group1=levels[0];   

        final String  groups []=getResources().getStringArray(R.array.group);
        String item1=groups[0];
        tw.setText(item1);

所以,请你给我身后这个问题的任何想法。我的最终目标是,选择Level1-> Group1->然后单击下一步按钮,出现在时间和反复1个字(写不完或循环方式)。

So, would you please give me any ideas behind this problem. My ultimate goal is, Choose Level1->Group1-> Then Click the next button and show up 1 word at time and repeatedly(Never finish or circular way).

推荐答案

所以,你要遍历一组串? 为什么不使用普通字符串和指标?

So you want to iterate over a group of strings? Why not using plain strings with indices?

<string name="string_deftype">string</string>
<string name="mylexicon_identifier">level_%1$d_group_%2$d_word_%3$d</string>

<string name="level_1_group_1_word_1">the</string>
<string name="level_1_group_1_word_2">the little boy</string>
....
<string name="level_2_group_2_word_1">i</string>
<string name="level_2_group_2_word_2">i can go</string>

,然后在活动或上下文

And then in your Activity or Context

this.getResources().getIdentifier(getString(R.string.mylexicon_identifier, index_level, index_group, index_word), getString(R.string.string_deftype), getApplicationContext().getPackageName()));

你基本上可以用这个做那么什么:

So what you basically can do with this:

loop levels
  loop groups
    loop words

而你必须检查你的循环,如果相应的资源存在(看看文件)

Whereas you have to check in your loops if the appropriate resource exists (look into the documentation)

getIdentifier() != 0

请记住,这种方法并不像所提到的文件中是很快速的。 我希望这有助于。

Keep in mind, that this approach is not a very fast one as mentioned in the documentation. I hope this helps.

PS:你也可以使用,当然数据库^^

PS: You could also use a database of course.^^

这篇关于如何访问字符串数组列表的XML结构如下的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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