R.string.value 帮助 android 通知
是怎么回事
CharSequence contentTitle = R.string.value;
错误无法从 int 转换为 CharSequence 。有办法解决这个问题还是我错过了什么? 我尝试过
String s = R.string.value + "";
CharSequence contentTitle = s;
它返回整数值。 有什么帮助吗?
whats the deal with
CharSequence contentTitle = R.string.value;
Error cannot convert from int to CharSequence. Is there a way around this or am i missing something?
i tried
String s = R.string.value + "";
CharSequence contentTitle = s;
it returns integers values.
Any help?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
R.string.value
是对 R 类中静态字段的调用,该字段由 Eclipse 自动生成,并对所有资源进行某种汇总。要检索字符串,您需要使用:如果打开 R 类,您将看到它仅包含对项目已编译资源的引用的数字。
R.string.value
is a call to the static field in the class R, which is auto generated by Eclipse and which does a kind of summary of all your resources. To retrieve the string, you need to use :If you open the R class you will see that it contains only numbers that are references to the compiled resources of your project.
要检索字符串,您需要使用 getString(),
但 getString() 是 Context 类中的方法。
如果您想在 Activity 类之外使用此方法,您应该首先获取到上下文的链接,然后调用:
To retrieve the string, you need to use getString(),
but getString() is a method from Context class.
If you want to use this method outside your Activity class, you should get link to your context first and then call:
R.string.value 返回资源“value”的引用 ID 号。如果您查看 R 类,它将显示为如下所示:
我在引用 getString() 方法时遇到了问题。 Eclipse 向我吐出的确切错误是:
阅读了一段时间后,我发现您必须引用应用程序的上下文才能访问 getString() 方法。我试图在内容提供程序中创建一个私有 SQLDatabase 帮助程序类,但是,这不允许我引用 getString() 方法。到目前为止,我的解决方案是执行以下操作:
注意这两个上下文引用:
我不知道这是否是最佳的长期解决方案,但目前看来可行。希望这有帮助。
R.string.value returns the reference ID number of the resource 'value'. If you look at your R class it will appear as something like this:
I've been experiencing issues with referencing the getString() method. The exact error that Eclipse spits at me is:
After reading for awhile I've figured out that you must reference your application's context to get access to the getString() method. I was trying to create a private SQLDatabase helper class in a content provider, however, that was not allowing me to reference the getString() method. My solution so far is to do something like this:
Notice these two context references:
I don't know if this is the optimal long-term solution but it seems to work for the moment. Hope this helps.
您也可以使用 String s = getResources().getString(R.string.value); 。
You could use
String s = getResources().getString(R.string.value);
also.