public class Dialogactivity extends Activity {
Progress dialog box
ProgressDialog ProgressDialog;
@Override
protected void OnCreate (Bundle savedinstancestate) {
Super.oncreate (savedinstancestate);
Setcontentview (R.layout.activity_main);
Dialog Dialog = new Alertdialog.builder (dialogactivity.this)
. Settitle ("Login Prompt")
Set Title
. Setmessage ("Login required here!") ")
Set content
. Setpositivebutton ("OK", newDialoginterface. Onclicklistener () {
@Override
public void OnClick (dialoginterface dialog, int whichbutton) {
Click OK to turn to the login box
layoutinflater layoutinflater = Layoutinflater
. from (dialogactivity.this);
//Get a custom dialog box
final View Dialogview = layoutinflater.inflate (
r.layout.dialog_login, null);
Create dialog box
Alertdialog dlg = new Alertdialog.builder (
dialogactivity.this). Settitle ("Login Box")
. Setview (Dialogview)
To set the style of a custom dialog box
. Setpositivebutton ("OK",//Set OK button
New Dialoginterface.onclicklistener () {//Set OK button Event listener
@Override
public void OnClick (
Dialoginterface Dialog,
int Whichbutton) {
Enter finish, click OK button to start login, Show progress dialog box
ProgressDialog = ProgressDialog
. Show (Dialogactivity.this,
"Please wait ...",
"is logging in for you ...",
true);
New Thread () {
public void Run () {
try {
Sleep (3000);
} catch (Exception e) {
E.printstacktrace ();
} finally {
End of login, cancel progress dialog box
ProgressDialog
. Dismiss ();
DialogActivity.this.finish ();//< self-added >
}
}
}. Start ();
}
}). Setnegativebutton ("Cancel",//Set Cancel button
New Dialoginterface.onclicklistener () {
@Override
public void OnClick (
Dialoginterface Dialog,
int Whichbutton) {
Click the Cancel button to exit the app
DialogActivity.this.finish ();
}
}). Create ();
Dlg.show ();
}
})
. Setneutralbutton ("Exit", new Dialoginterface.onclicklistener () {
@Override
public void OnClick (dialoginterface dialog, int whichbutton) {
Click the Exit button to exit the application
DialogActivity.this.finish ();
}
}). Create ();Create button
Show dialog box
dialog.show ();
}
}
Android--dialog