Android--dialog

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.