1

我正在尝试button在我的 中插入一个 to rate 应用程序,如果找不到市场,则activity使用for。toast但我Context cannot be resolved to a variable在 Activity.this 上得到一个“”:

Uri uri = Uri.parse("market://details?id=" + getApplicationContext().getPackageName());
Intent goToMarket = new Intent(Intent.ACTION_VIEW, uri);
try {
    startActivity(goToMarket);
} catch (ActivityNotFoundException e) {
    Toast.makeText(Activity.this, "Couldn't launch the market", Toast.LENGTH_LONG).show();
}

我也试过:

Toast.makeText(this, "Couldn't launch the market", Toast.LENGTH_LONG).show();

但是后来我在这一行得到了多个标记 - makeText(Context, CharSequence, int)Toast 类型中的方法不适用于参数(new View.OnClickListener(){}, String, int)

我以前用button toast同样的方法(没有try/ catch)做了一个简单的方法,然后它工作得很好。我做错了什么?

4

4 回答 4

3

如果您的课程使用 Activity 进行扩展,则意味着像这样使用

Toast.makeText(ClassName.this, "Couldn't launch the market",Toast.LENGTH_LONG).show();

或者

Toast.makeText(getApplicationContext(), "Couldn't launch the market",Toast.LENGTH_LONG).show();

如果您的 Class 使用 Fragment 进行扩展,则意味着使用如下:

Toast.makeText(getActivity(), "Couldn't launch market",Toast.LENGTH_LONG).show();
于 2013-12-06T12:23:36.723 回答
0

尝试:

Toast.makeText(getApplicationContext(), "Couldn't launch the market", Toast.LEGTH_LONG).show();
于 2013-12-06T12:17:48.640 回答
0

您的答案:

Toast.makeText(getApplicationContext(), "Couldn't launch the market", Toast.LENGTH_LONG).show();
于 2013-12-06T12:18:44.440 回答
0

尝试这个...

Uri uri = Uri.parse("market://details?id="
                + getApplicationContext().getPackageName());
        Intent goToMarket = new Intent(Intent.ACTION_VIEW, uri);
        try {
            startActivity(goToMarket);

        } catch (ActivityNotFoundException e) {
            this.runOnUiThread(new Runnable() {

                @Override
                public void run() {
                    Toast.makeText(getApplicationContext(),
                            "Couldn't launch the market", Toast.LENGTH_LONG)
                            .show();
                }
            });
        }

希望对你有帮助...

于 2013-12-06T12:29:45.410 回答