在Android中创建AlertDialog需要建议吗

在Android中创建AlertDialog需要建议吗,android,android-alertdialog,Android,Android Alertdialog,当在我的活动中按下按钮时,我会调用以下代码 AlertDialog.Builder alertDialog = new AlertDialog.Builder(this).create(); alertDialog.setTitle("Alert 1"); alertDialog.setMessage("This is an alert"); alertDialog.setButton("OK", new Dia

当在我的活动中按下按钮时,我会调用以下代码

AlertDialog.Builder alertDialog = new AlertDialog.Builder(this).create();  
            alertDialog.setTitle("Alert 1");  
            alertDialog.setMessage("This is an alert");  
            alertDialog.setButton("OK", new DialogInterface.OnClickListener() {  
              public void onClick(DialogInterface dialog, int which) {  
                return;  
            } });  
我添加了以下两种导入:

import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
但仍然会出现以下错误:

Description Resource    Path    Location    Type
The constructor AlertDialog.Builder(new View.OnClickListener(){}) is undefined  MobileTrackerActivity.java  /MobileTracker/src/com/example/mobiletracker    line 77 Java Problem
The method setButton(String, new DialogInterface.OnClickListener(){}) is undefined for the type AlertDialog.Builder MobileTrackerActivity.java  /MobileTracker/src/com/example/mobiletracker    line 80 Java Problem
Type mismatch: cannot convert from AlertDialog to AlertDialog.Builder   MobileTrackerActivity.java  /MobileTracker/src/com/example/mobiletracker    line 77 Java Problem

谁能给我一个解决办法吗?我对Java非常陌生。

如果您查看此页面:

您只需进行以下更改即可收到错误消息:

AlertDialog alertDialog = new AlertDialog.Builder(this).create();

如果您查看此页面:

您只需进行以下更改即可收到错误消息:

AlertDialog alertDialog = new AlertDialog.Builder(this).create();

通过以下方式创建AlertDilog:

   AlertDialog.Builder alertDialog = new AlertDialog.Builder(this);  
   alertDialog.setTitle("Alert 1");  
   alertDialog.setMessage("This is an alert");  
   alertDialog.setButton("OK", new DialogInterface.OnClickListener() {  
   public void onClick(DialogInterface dialog, int which) {  
        return;  
   } });  
   AlertDialog alert = alertDialog.create();
   alert.show();

通过以下方式创建AlertDilog:

   AlertDialog.Builder alertDialog = new AlertDialog.Builder(this);  
   alertDialog.setTitle("Alert 1");  
   alertDialog.setMessage("This is an alert");  
   alertDialog.setButton("OK", new DialogInterface.OnClickListener() {  
   public void onClick(DialogInterface dialog, int which) {  
        return;  
   } });  
   AlertDialog alert = alertDialog.create();
   alert.show();