我创建了以下结构.这里的级别最多为4,组最多为6个相同的xml文件结构.但是我无法访问level1 – > group1->第一项,也有项目.总共有4个级别,每个级别有6个单独的组,每个组有10个单独的项目.
<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>
这里有一些代码,我试试….
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个单词(从不完成或循环方式).
解决方法:
所以你想迭代一组字符串?
为什么不使用带索引的普通字符串?
<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>
然后在您的活动或上下文中
this.getResources().getIdentifier(getString(R.string.mylexicon_identifier, index_level, index_group, index_word), getString(R.string.string_deftype), getApplicationContext().getPackageName()));
所以你基本上可以做到这一点:
loop levels
loop groups
loop words
如果存在适当的资源,你必须检查你的循环(查看文档)
getIdentifier() != 0
请记住,这种方法并不像文档中提到的那么快.
我希望这有帮助.
PS:当然你也可以使用数据库.^^
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。