我的代码是:安卓:Java的:在吐司使用字符串资源
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中。我试图让准备本地化我的应用程序(让所有的硬编码字符串到资源),所以我哪里有:
getString(R.string.toast_memoryshort)
我以前这是一个硬编码字符串的罚款。
我不确定这里发生了什么(Java noob)。任何人都可以启发我吗?
非常感谢
巴兹
非常感谢Stefan,完美。 – Barry
实际上,它是你的答案和Rasel的组合:在结尾需要.show,在资源ID:Toast.makeText(上下文,R.string.toast_memoryshort,Toast.LENGTH_LONG)之前不需要Rasel的“+” 。显示();所以对Rasel也是+1。非常感谢。 – Barry
是的,当然.show()是需要的:) –