In Android, creating a dialog box is relatively simple. New alertdialog. Builder is used to set its information, such as the displayed content, title, whether the dialog box can be canceled by the Return key, OK, and cancel buttons.
,
new AlertDialog.Builder(EX03_12.this)
.setTitle(R.string.app_about)
.setMessage(R.string.app_about_msg)
.setCancelable(false)
.setPositiveButton(R.string.str_ok,
new DialogInterface.OnClickListener()
{
public void onClick(DialogInterface dialoginterface, int i)
{
}
})
.setNegativeButton(R.string.str_cancel,
new DialogInterface.OnClickListener()
{
@Override
public void onClick(DialogInterface dialog, int which)
{
// TODO Auto-generated method stub
finish();
}
}).show();
Setcancelable (false) indicates that you cannot use the return key on your phone to cancel the dialog box. setpositivebutton () and. setnegativebutton () respectively set the events of the confirm button and the events of the cancel button.