1.dialog box notification (Dialog Notification)
You can use a dialog box when your app needs to display a progress bar or if the user needs to confirm the information.
The following code opens a dialog box:
Public voidclick1 (view view) {Alertdialog.builder Builder=NewBuilder ( This); Builder.settitle ("Engineering Building No. 1th"); Builder.seticon (R.drawable.ic_launcher); Builder.setmessage ("Browse Wuyudong's blog?" )); Builder.setpositivebutton ("OK",NewOnclicklistener () {@Override Public voidOnClick (Dialoginterface Dialog,intwhich) {URI Uri= Uri.parse ("http://www.wuyudong.com/");//Open LinkIntent Intent =NewIntent (Intent.action_view, URI); StartActivity (Intent); } }); Builder.setnegativebutton ("Cancel",NewOnclicklistener () {@Override Public voidOnClick (Dialoginterface Dialog,intwhich) {Dialog.cancel (); } }); Alertdialog Dialog=builder.create (); Dialog.show (); }
This article address: http://www.cnblogs.com/wuyudong/p/5854896.html, reprint please indicate source address.
2. Create a dialog box with a list of single options
Public voidClick2 (view view) {Alertdialog.builder Builder=NewBuilder ( This); Builder.settitle ("Radio dialog box"); Finalstring[] Items =NewString[] {"Java", ". Net", "PHP" }; Builder.setsinglechoiceitems (Items,0,NewOnclicklistener () {@Override Public voidOnClick (Dialoginterface Dialog,intwhich) {Toast.maketext (mainactivity). This, Items[which] + "clicked", 0). Show (); } }); Builder.show (); }
3. Create a dialog box with a multi-option list
Public voidClick3 (view view) {Alertdialog.builder Builder=NewBuilder ( This); Builder.settitle (Multi-Select dialog box); Finalstring[] Items =NewString[] {"Java", ". Net", "PHP", "C + +" }; Builder.setmultichoiceitems (Items,New Boolean[] {true,false,false, true},NewOnmultichoiceclicklistener () {@Override Public voidOnClick (Dialoginterface Dialog,intwhich,BooleanisChecked) {Toast.maketext (mainactivity). This, Items[which] + isChecked, 0). Show (); } }); Builder.setnegativebutton ("Cancel",NewOnclicklistener () {@Override Public voidOnClick (Dialoginterface Dialog,intwhich) {Dialog.cancel (); } }); Builder.show (); }
4.Progress dialog box (ProgressDialog)
Use code progressdialog.show (progressdialogactivity.this, "Please Wait", "data is loading ...", true); Create and display a progress dialog box.
Call the Setprogressstyle () method to set the progress dialog box style. There are two types of styles:
Progressdialog.style_spinner Rotation progress bar style (default style)
Progressdialog.style_horizontal Horizontal progress bar Style
Public void Click4 (view view) { new progressdialog (this); Pd.settitle ("Reminder"); Pd.setmessage ("Loading in ..."); Pd.show (); }
The following code implements the horizontal progress bar style:
Public voidclick5 (view view) {FinalProgressDialog PD =NewProgressDialog ( This); Pd.setprogressstyle (progressdialog.style_horizontal); Pd.setmax (100); Pd.show (); NewThread () { Public voidrun () { for(inti = 0; I < 100; i++) {pd.setprogress (i); Try{Thread.Sleep (20); } Catch(interruptedexception e) {e.printstacktrace (); }} Pd.dismiss (); }; }.start (); }
Android Common dialog box