Android - 使用另一个字符串引用字符串数组以避免使用 SQLite

发布于 2024-12-06 12:46:17 字数 512 浏览 0 评论 0原文

我已经搜索过这个,但我不太确定我应该搜索什么。

我试图避免使用 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技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

断舍离 2024-12-13 12:46:17

如果我猜对了你需要的是 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文