在Toast中使用字符串资源 [英] using a string resource in a Toast
问题描述
我的代码是:
public static void ToastMemoryShort (Context context) {
CharSequence text = getString(R.string.toast_memoryshort); //error here
Toast.makeText(context, text, Toast.LENGTH_LONG).show();
return;
}
但我得到无法对非静态进行静态引用方法getString(int)来自Eclipse中的类型Context。我正在准备本地化我的应用程序(将所有硬编码字符串转换为资源),所以我在哪里:
but I'm getting "Cannot make a static reference to the non-static method getString(int) from the type Context" in Eclipse. I'm trying to get ready for localising my app (getting all the hard coded strings into resources), so where I have:
getString(R.string.toast_memoryshort)
我以前有一个硬编码的字符串,这很好。
I previously had a hard coded string which was fine.
我不确定这里发生了什么(Java noob)。请允许任何人开导我吗?
I'm not sure what's going on here (Java noob). Can anyone enlighten me please?
非常感谢
Baz
推荐答案
只需改用:
makeText(Context context,int resId,int持续时间)制作一个标准的
吐司,它只包含一个带有资源文本的文本视图。
makeText(Context context, int resId, int duration) Make a standard toast that just contains a text view with the text from a resource.
来自 http://developer.android.com/reference/android/widget/Toast.html
这篇关于在Toast中使用字符串资源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!