在 Android 中创建 XML 整数列表
我想在 android 项目的 /res 文件夹中创建一个整数列表。但是,我希望这些整数指向 /res/raw 中的资源。例如,我想要这样的东西:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<integer-array name="built_in_sounds">
<item>@raw/sound</item>
</integer-array>
</resources>
但是 id 看起来我不能做到这一点,有什么办法可以做到这一点吗?或者我应该在 java 类中创建列表?
谢谢
I would like to create a list of Integers in the /res folder of an android project. However, I want those integers to point resources in /res/raw. So for example, I would like something like this:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<integer-array name="built_in_sounds">
<item>@raw/sound</item>
</integer-array>
</resources>
But id doesn't look like I can do that, is there any way to do this? Or should I just create the list in a java class?
Thank you
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
正确的答案实际上是 TypedArray
文档显示资源列表的示例:
以及检索值的代码:
And the correct answer is actually, TypedArray
The documentation shows examples of lists of resources:
And the code to retrieve the values:
好吧,我终于知道如何做到这一点了。我所做的只是创建一个数据库。数据库存储了我需要存储的所有原语,以及指向我需要引用的对象的指针。显然 android SDK 附带了对 SQLite 的支持。
Okay, I finally found out how to do this. What I did, was just create a database. The database stored all of the primitives I needed to store, and than pointers to the objects that I needed to reference. Apparently the android SDK comes with support for SQLite.
要在不使用数据库的情况下在 XML 中执行此操作,请参阅:
http://developer.android.com/guide/topics/资源/more-resources.html#Integer
To do this in XML without a database, see:
http://developer.android.com/guide/topics/resources/more-resources.html#Integer