Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Dialog Box without buttons

Tags:

android

Can i create a dialog box without negative or positive buttons. That destroys it self after specific action?

 AlertDialog.Builder dialog_detect= new AlertDialog.Builder(MainActivity.this);
 dialog.setTitle("Detecting.....");
 dialog.setMessage("Please Wait");
 dialog.show();
like image 350
user2401745 Avatar asked Aug 01 '13 12:08

user2401745


People also ask

Can you have an alert dialog without any buttons if not why?

You can do this very easily. AlertDialog. Builder alertDialogBuilder = new AlertDialog. Builder(context); // set title alertDialogBuilder.

How do I get alert dialog box?

setTitle(CharSequence title)AlertDialog alertDialog = alertDialogBuilder. create(); alertDialog. show(); This will create the alert dialog and will show it on the screen.


1 Answers

You can do this very easily.

AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(context);

// set title
alertDialogBuilder.setTitle("Your Title");

// set dialog message
alertDialogBuilder.setMessage("Message here!").setCancelable(false);

// create alert dialog
AlertDialog alertDialog = alertDialogBuilder.create();

// show it
alertDialog.show();

// After some action
alertDialog.dismiss();

If you have a reference to the AlertDialog somewhere else, you can still call alertDialog.dismiss(). This closes the dialog.

like image 65
crocboy Avatar answered Oct 03 '22 03:10

crocboy