需要在 Android 中创建 AlertDialog 的建议
当在我的活动中按下按钮时,我会调用以下代码。
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 很陌生。
I have the following code called when a button is pressed in my activity.
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;
} });
I have added imports these two :
import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
But still get following errors :
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
Can anybody give any solution to me please? I am very new to Java.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这样创建 AlertDilog :
Create the AlertDilog this way :
如果您查看此页面:
http://developer.android.com/guide/ topic/ui/dialogs.html
和您收到的错误消息您只需要进行以下更改:
If you look at this page:
http://developer.android.com/guide/topics/ui/dialogs.html
and the error message you get you just need to make this change: