静态资源文件?
Android 使用静态资源文件R
。当您添加任何类型的新 ID 时,此文件(至少在 Eclipse 中)会自动更新。如何在普通的 java 应用程序中创建/实现相同的功能?难道只是写一个xml解析器,修改xml后更新资源文件那么简单吗?
Android uses a static resource file R
. This file (at least in eclipse) is automatically updated when ever you add new id's of any sort. How can I create/implement the same feature in a normal java application? Is it as simple as just writing an xml parser and just updating the resource file after the xml is modified?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在某种程度上,是的。您需要创建一个自定义构建脚本/程序,该脚本/程序在每次构建开始时运行(在其他任何事情之前),扫描您的资源文件夹文件(如果它们是 XML 文件,则需要读入 XML 文件并解析出字符串资源或其中的任何内容),然后以某种方式将其全部写入 Java 文件(例如 R.string_name =“字符串值”)。
确保 XML 文件实际上并未打包在您的 .jar 中,因为所有这些信息现在都将存储在您的 Java 资源文件中。
对于不是 XML 文件的内容,您可以将文件名作为字符串存储在 Java 资源文件中。
In a way, yes. You need to create a custom build script/program which runs at the start of each build (before anything else), scans your resource folder files (and if they are XML files it needs to read in the XML files and parse out the string resources or whatever from those), then write it all to a Java file in some manner (e.g. R.string_name = "string value").
Make sure the XML files aren't actually packaged in your .jar, since all that information will be stored inside your Java resources file now.
For things which aren't XML files you could just store the filename as a string in the Java resources file.
您没有指定资源的类型或用途。我不懂android,但我会尽力提供帮助;如果您只需要访问应用程序中的某些资源,您可以使用属性或资源,但存在一些差异,请参阅其他问题属性与资源包
You didn't specified the type or the use of the resources. I don't know android, but I'll try to help; If you just need to access some resource in your application you can use properties or resource, there are some differences see this other question Properties vs Resource Bundle