一个例子中的一行代码: AlertDialog dlg = new AlertDialog.Builder(this); 输入后提示错误:    Type mismatch: cannot convert from AlertDialog.Builder to AlertDialog 错在什么地方?  怎样写才能声明一个对话框对象?

解决方案 »

  1.   

     AlertDialog dlg = new AlertDialog.Builder(this,Title,Message,事件);如:
    AlertDialog dialog = new AlertDialog.Builder(this)
    .setIcon(R.drawable.icon)
    .setTitle("退出对话框")
    .setMessage("您真的要退出吗")
    .setNegativeButton("取消",
    new DialogInterface.OnClickListener() {
    @Override
    public void onClick(DialogInterface dialog,
    int which) {
    }
    })
    .setPositiveButton("确定",
    new DialogInterface.OnClickListener() {
    public void onClick(DialogInterface dialog,
    int whichButton) {
    LocalInfoActivity.this.finish();
    }
    }).create();
    dialog.show();
      

  2.   

    楼主看来不知道java的Builder机制
      

  3.   

    你应该看看 Builder  返回的是什么  
    而不是AlertDialog返回的是什么估计LZ是C++ 出生?
      

  4.   

    AlertDialog.Builder adb=new AlertDialog.Builder(this);
            adb.setTitle("提示");
            adb.setMessage("kkkkkkkk");
            adb.setIcon(R.drawable.icon);
            adb.setNegativeButton("取消", null);
           adb.create().show();楼主用这个!!!
      

  5.   

    这样写:
    AlertDialog dlg = new AlertDialog.Builder(this).create();应该就对了