Android Common Dialog Box and android dialog box
1. Dialog Box Notification)
You can use a dialog box to display a progress bar or confirm the information of your application.
The following code opens a dialog box:
Public void click1 (View view) {AlertDialog. builder builder = new Builder (this); builder. setTitle ("School of Engineering 1"); 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 the 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 ();}
URL: http://www.cnblogs.com/wuyudong/p/5854896.html.
2. Create a dialog box with a single option list
Public void click2 (View view) {AlertDialog. builder builder = new Builder (this); builder. setTitle ("single choice 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
Public void click3 (View view) {AlertDialog. builder builder = new Builder (this); builder. setTitle ("Multi-choice 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 the code ProgressDialog. show (ProgressDialogActivity. this, "Please wait", "data loading...", true); Create and display a progress dialog box.
Call setProgressStyle () to set the style of the Progress dialog box. There are two styles:
ProgressDialog. STYLE_SPINNER progress bar 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(100); pd.show(); new Thread() { public void run() { for (int i = 0; i < 100; i++) { pd.setProgress(i); try { Thread.sleep(20); } catch (InterruptedException e) { e.printStackTrace(); } } pd.dismiss(); }; }.start(); }