问题描述
我有一个字符串就像字符串数据=应用程序;
我知道加载的字符串在Android中有两种方式。
第一个是
所以它是一个恒定的我把它定义为
公共静态最终字符串数据=应用程序;
和其他类型的defing它 RES / vslues / strings.xml中
文件如..
<字符串名称=数据>应用程序< /串>
<字符串名称=参考hello world>世界,你好<!/串>
如果我想使用它..
对于第一种方式 ClassName.data
对于第二种方式
context.getResources()的getString(RESOURCEID)
解决方案
不过,速度应该不是真的在这两种情况下的问题。我建议组织根据情理之中的事情。
常量类
把,将在内部使用,如数据库列名或其他键的字符串常量。
的strings.xml
将被显示给用户的字符串。这样,您就可以利用本地化等。
I have a String is like String data="apps";
i know loading String in Android in two ways..
First one is
so it is a constant i defined it as
public static final String data="apps";
And another type is defing it in res/vslues/strings.xml
file like..
<string name="data">apps</string>
<string name="hello_world">Hello world!</string>
if i want to use it..
for the first way ClassName.data
for second way context.getResources().getString(resourceid)
解决方案 However, speed shouldn't really be an issue in either case. I would recommend organizing based on what makes sense.
Constants class
Put strings constants that will be used internally, like database column names or other keys.
strings.xml
Put strings that are displayed for the user. This way you can take advantage of localization, etc.
这篇关于XML字符串资源VS Java的常量字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!