首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 移动开发 > Android >

关于android对话框解决方案

2012-08-11 
关于android对话框一个例子中的一行代码:AlertDialog dlg new AlertDialog.Builder(this)输入后提示错

关于android对话框
一个例子中的一行代码:

 AlertDialog dlg = new AlertDialog.Builder(this);

 输入后提示错误:

  Type mismatch: cannot convert from AlertDialog.Builder to AlertDialog

 错在什么地方?

  怎样写才能声明一个对话框对象?

[解决办法]
AlertDialog dlg = new AlertDialog.Builder(this,Title,Message,事件);

如:

Java code
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();
[解决办法]
楼主看来不知道java的Builder机制
[解决办法]
你应该看看 Builder 返回的是什么
而不是AlertDialog返回的是什么

估计LZ是C++ 出生?

[解决办法]
AlertDialog.Builder adb=new AlertDialog.Builder(this);
adb.setTitle("提示");
adb.setMessage("kkkkkkkk");
adb.setIcon(R.drawable.icon);
adb.setNegativeButton("取消", null);
adb.create().show();

楼主用这个!!!

热点排行