开发者

How can i use ShowDialog?

I was reading about Android, and it was an method ShowAlert, but a friend tell me that ShowAlert was updated to ShowDialog but i dont know how to use it. Can anyone tell me how c开发者_C百科an i use it???

Thanks!


Here is an example function from my code in one of my Activity classes:

protected void FatalError(String message)
{
  AlertDialog.Builder alertbox = new AlertDialog.Builder(this); // this - refers to an Activity
  alertbox.setMessage(message);
  alertbox.setNeutralButton("Exit", new DialogInterface.OnClickListener() {
    public void onClick(DialogInterface arg0, int arg1) {
      finish();
    }
  });
  alertbox.show();
}

The goal of the function would be to pop up a message, and when the user clicked on the 'Exit' button, it would close the activity.


In android you can create following types of dialog : AlertDialog ProgressDialog DatePickerDialog TimePickerDialog

Apart from these you can also create your own custom dialog.

For alter Dialog you have to use class AlertDialog.

First you set properties of alert dialog by creating builder of dialog as:

AlertDialog.Builder builder = new AlertDialog.Builder(this);

Now you can set some of properties of this builder by using some functions like setMessage(), setCancelable(),setPositiveButton(),setNegativeButton() etc.

Last step is to create your dialog. For this: AlertDialog alert builder.create();

and then you can use alert.show() to display your alert.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜