2013-09-12 回答
用我这个, 我己经给你写好了,你可以稍做修改就能用,
title是对话框的标题
icon是resid,是一张图片的id,放在你res目录下的drawable
okcmd和cancelcmd分别是确认和取消按钮的字符串
//确认对话框的呼出
public void showdialog(string title,int icon,string msg,string okcmd,string cancelcmd){
if(okcmd==null){return;}
log.i("setdialog", "dialogtitle="+title
+" dialogcontent"+msg+
" dialogcmdok"+okcmd
+" dialogcmdcancel"+cancelcmd
+" dialogicon"+icon);
builder builder=new alertdialog.builder(this);
builder.settitle(title);
if(icon>0){
builder.seticon(icon);
}else{
builder.seticon(r.drawable.icon);
}
builder.setmessage(msg);
builder.setpositivebutton(okcmd,
new
android.content.dialoginterface.onclicklistener(){
public void onclick(dialoginterface d, int i) {
log.i("showdialog", "onclick");
}
});
if(cancelcmd!=null && cancelcmd.length()>0){
builder.setneutralbutton(cancelcmd,
new android.content.dialoginterface.onclicklistener(){
public void onclick(dialoginterface d, int i) { }
});
}
alertdialog dialog =builder.create();
dialog.show();
}