Android - 使用另一个字符串引用字符串数组以避免使用 SQLite
我已经搜索过这个,但我不太确定我应该搜索什么。
我试图避免使用 SQLite DB,并且想知道是否可以使用另一个字符串的值来调用字符串。
例如。
如果我在 xml 文件中有这样的内容:
<string-array name="bob">
<item>1</item>
<item>4</item>
<item>7</item>
<item>11</item>
</string-array>
在 Java 文件中有这样的内容:
String name = "bob";
那么我可以做这样的事情吗:
String[] holder = getResources().getStringArray(R.array.name);
谢谢!
I've searched for this but I'm not exactly sure what I should be searching for.
I'm trying to avoid using a SQLite DB and was wondering is it possible to call a string using the value of another string.
Eg.
If I have in a xml file this:
<string-array name="bob">
<item>1</item>
<item>4</item>
<item>7</item>
<item>11</item>
</string-array>
And in a Java file this:
String name = "bob";
can I then do something like this:
String[] holder = getResources().getStringArray(R.array.name);
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
![扫码二维码加入Web技术交流群](/public/img/jiaqun_03.jpg)
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果我猜对了你需要的是 getIdentifier()。考虑到这种方法的成本很高,而且通过标识符检索资源的效率要高得多。
If I guess correctly what you are needing is getIdentifier(). Take into account that this method is expensive and it is much more efficient to retrieve resources by identifier.