安卓:Java的:在吐司使用字符串资源 [英] Android: Java: using a string resource in a Toast

查看:250
本文介绍了安卓:Java的:在吐司使用字符串资源的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的code是:

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。我试图让准备本地化我的应用程序(让所有的硬codeD字符串资源化),所以在这里我有:

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)

我previously了这是很好的硬codeD字符串。

I previously had a hard coded string which was fine.

我不知道是怎么回事就在这里(Java的小白)。任何人都可以赐教吗?

I'm not sure what's going on here (Java noob). Can anyone enlighten me please?

非常感谢

巴兹

推荐答案

只要使用这个代替:

makeText(上下文的背景下,诠释渣油,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

这篇关于安卓:Java的:在吐司使用字符串资源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆