a1670131049
a1670131049
2019-10-27 18:28

安卓对话框中显示Toast问题

  • android
        Builder builder=new Builder(this);
        builder.setTitle("单选框");
        builder.setMessage("有本事你选");
        builder.setPositiveButton("确定", new OnClickListener(){
            public void onClick(DialogInterface arg0, int arg1) {
                Toast.makeText(this, "你选了确定", 0).show();
            }
        });

Toast.makeText(this, "你选了确定", 0).show();
这句话把getApplicationContext()替换成this 会报错:
The method makeText(Context, CharSequence, int) in the type Toast is not applicable for the arguments (new DialogInterface.OnClickListener(){}, String, int)

为什么不能用this?

  • 点赞
  • 回答
  • 收藏
  • 复制链接分享

2条回答

为你推荐

换一换