Dialog dialog = new AlertDialog.Builder(AlertDialogSamples.this) .setIcon(R.drawable.alert_dialog_icon) .setTitle(“title”) .setMessage(“这里是提示信息语句”) .setPositiveButton(“Ok”, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) {
/* User clicked OK so do some stuff */ } }) .setNeutralButton(“Cancel”, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) {
/* User clicked Something so do some stuff */ } }) .setNegativeButton(R.string.alert_dialog_cancel, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) {
/* User clicked Cancel so do some stuff */ } }) .create(); dialog.show();//如果要显示对话框,一定要加上这句
public class TextEntryDialogTest extends Activity { Button btnTEDlg;
/** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main);
@Override public void onClick(View v) { LayoutInflater factory = LayoutInflater.from(TextEntryDialogTest.this); final View textEntryView = factory.inflate(R.layout.text_entry_dialog, null); AlertDialog dlg = new AlertDialog.Builder(TextEntryDialogTest.this) .setTitle("User Login") .setView(textEntryView) .setPositiveButton("OK", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) {
/* User clicked OK so do some stuff */ } }) .setNegativeButton("Cancel", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) {
/* User clicked cancel so do some stuff */ } }) .create(); dlg.show(); } }); } }