1, dialog box notification (Dialog Notification)
When your application needs to display a progress bar or require the user to confirm the information, you can use the dialog box to complete it.
The following code opens a dialog box as shown in the illustration:
public void Click1 (view view) {
Alertdialog.builder Builder = new Builder (this);
Builder.settitle ("Hall No. 1th");
Builder.seticon (r.drawable.ic_launcher);
Builder.setmessage ("Browse Wuyudong's blog?");
Builder.setpositivebutton (OK), new Onclicklistener () {
@Override public
void OnClick (Dialoginterface dialog , int which) {
uri uri = uri.parse ("http://www.wuyudong.com/");//Open link
Intent Intent = new Intent (intent.action_ VIEW, URI);
StartActivity (intent);
}
);
Builder.setnegativebutton ("Cancel", new Onclicklistener () {
@Override public
void OnClick (dialoginterface dialog, int which) {
dialog.cancel ();
}
});
Alertdialog dialog = Builder.create ();
Dialog.show ();
}
2. Create a dialog box with a single list of options
public void Click2 (view view) {
Alertdialog.builder Builder = new Builder (this);
Builder.settitle ("Radio dialog Box");
Final string[] items = new string[] {"Java", ". Net", "PHP"};
Builder.setsinglechoiceitems (items, 0, new Onclicklistener () {
@Override public
void OnClick (dialoginterface dialog, int which) {
toast.maketext (mainactivity.this, Items[which] + "clicked", 0). Show
();
Builder.show ();
}
3. Create a dialog box with multiple options list
public void Click3 (view view) {
Alertdialog.builder Builder = new Builder (this);
Builder.settitle ("Multiple selection dialog box");
Final string[] items = new string[] {"Java", ". Net", "PHP", "C + +"};
Builder.setmultichoiceitems (items, new boolean[] {true, False, False,
true}, new Onmultichoiceclicklistener () {
@Override public
void OnClick (dialoginterface dialog, int which,
Boolean ischecked) {
Toast.maketext ( Mainactivity.this, Items[which] + ischecked, 0)
. Show (();
}
);
Builder.setnegativebutton ("Cancel", new Onclicklistener () {
@Override public
void OnClick (dialoginterface dialog, int which) {
dialog.cancel ();
}
});
Builder.show ();
}
4. Progress dialog box (ProgressDialog)
Use code progressdialog.show (progressdialogactivity.this, "Wait a Minute", "Data is loading ...", true), and create and display a progress dialog box.
Call the Setprogressstyle () method to set the progress dialog style. There are two different styles:
Progressdialog.style_spinner style (default style)
Progressdialog.style_horizontal horizontal progress bar style public
void Click4 ( View view) {
ProgressDialog pd = new ProgressDialog (this);
Pd.settitle ("Reminder");
Pd.setmessage ("Loading ...");
Pd.show ();
}
The following code implements the horizontal progress bar style:
public void Click5 (view view) {
final progressdialog pd = new ProgressDialog (this);
Pd.setprogressstyle (progressdialog.style_horizontal);
Pd.setmax (m);
Pd.show ();
New Thread () {public
void run () {(
int i = 0; i < i++) {
pd.setprogress (i);
try {
thread.sleep;
} catch (Interruptedexception e) {
e.printstacktrace ()
}} Pd.dismiss ();
};
Start ();
The above is a small set to introduce Android common four kinds of dialog box examples to explain, I hope to help you, if you have any questions please give me a message, small series will promptly reply to everyone. Here also thank you very much for the cloud Habitat Community website support!