protected Dialog onCreateDialog(int id) { if (id == 0) {// 注销 AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setMessage("你确认要注销吗?") .setCancelable(false) .setPositiveButton("确定", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { Talktalk.con.disconnect(); Intent intent = new Intent();// 设置跳转数据传输intent intent.setClass(Frilist.this, Talktalk.class); intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); startActivity(intent); finish(); } }).setNegativeButton("取消", null); AlertDialog alert = builder.create(); return alert; } else {//邀请好友对话框 final EditText input = new EditText(this); return new AlertDialog.Builder(this) .setTitle("请输入好友账号") .setView(input) .setPositiveButton("确定", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { String value = input.getText().toString(); setTitle(value); } }).setNegativeButton("取消", null).create(); } } 调用方法: showDialog(0); showDialog(1);