Step by Step _android Development Course [18]_ User Interface Dialog (dialog box)

Source: Internet
Author: User

Focus on technology, enjoy life! --qq:804212028
Browse Links: http://blog.csdn.net/y18334702058/article/details/44624305

    • Topic: Dialog of the User Interface (dialog box)

Dialog (dialog box) instance:

Activity_main.xml Source code:

<?xml version= "1.0" encoding= "Utf-8"?><linearlayout  xmlns: Android  = "http://schemas.android.com/apk/res/android"  android:orientation  =" vertical " android:layout_width  = "fill_parent"  android:layout_height  = "fill_parent" ;     <button  android:id  = "@+id/btn1"  android:layout_height  =< Span class= "Hljs-value" > "wrap_content"  android:layout_width  = "fill_parent"  android:text  =  "simple Dialog" />     <button  android:id  = "@+id/btn2"  android:layout_height  =< Span class= "Hljs-value" > "wrap_content"  android:layout_width  = "fill_parent"  android:text  =  "List selection box" />     <button  android:id  = "@+id/btn3"  android:layout_height  =< Span class= "Hljs-value" > "wrap_content"  android:layout_width  = "fill_parent"  android:text  =  "First progress bar box" />     <buttonandroid:id="@+id/btn4"android:layout_height="Wrap_ Content "android:layout_width=" Fill_parent "android:text=" Second progress bar box " />                                  </linearlayout>

Mainactivity.java Source code:

Importandroid.app.Activity;ImportAndroid.app.AlertDialog;ImportAndroid.app.ProgressDialog;ImportAndroid.content.DialogInterface;ImportAndroid.os.Bundle;ImportAndroid.view.LayoutInflater;ImportAndroid.view.View;ImportAndroid.view.View.OnClickListener;ImportAndroid.widget.Button;ImportAndroid.widget.EditText;ImportAndroid.widget.Toast; Public  class mainactivity extends Activity implements Onclicklistener {    PrivateButton Btn1,btn2,btn3,btn4,btn5,btn6,btn7,btn8;@Override    protected void onCreate(Bundle savedinstancestate) {Super. OnCreate (Savedinstancestate);        Setcontentview (R.layout.activity_main);    Init (); }Private void Init() {btn1 = (Button) Findviewbyid (R.ID.BTN1); Btn1.setonclicklistener ( This);        BTN2 = (Button) Findviewbyid (R.ID.BTN2); Btn2.setonclicklistener ( This);        Btn3 = (Button) Findviewbyid (R.ID.BTN3); Btn3.setonclicklistener ( This);        Btn4 = (Button) Findviewbyid (R.ID.BTN4); Btn4.setonclicklistener ( This); }@Override     Public void OnClick(View v) {Switch(V.getid ()) { CaseR.id.btn1:alertdialog.builder Builder0 =NewAlertdialog.builder (mainactivity. This);            Builder0.seticon (R.drawable.ic_launcher); Builder0.settitle ("dialog box"); Builder0.setmessage ("Are you ready to go to soy sauce?" ");//Set Positive button eventsBuilder0.setpositivebutton ("Confirm",NewDialoginterface.onclicklistener () { Public void OnClick(Dialoginterface arg0,intARG1) {Toast.maketext (mainactivity. This,"clicked-Confirm", Toast.length_short). Show (); }            });//Set Negative button eventsBuilder0.setnegativebutton ("Cancel",NewDialoginterface.onclicklistener () { Public void OnClick(Dialoginterface arg0,intARG1) {Toast.maketext (mainactivity. This,"Clicked--Cancel", Toast.length_short). Show ();            }            }); Builder0.create (). Show (); Break; CaseR.ID.BTN2:FinalString[] Mitems = {"Item0","Item1","Itme2","Item3","Itme4","ITEM5","Item6"}; Alertdialog.builder Builder1 =NewAlertdialog.builder (mainactivity. This); Builder1.settitle ("List selection box"); Builder1.setitems (Mitems,NewDialoginterface.onclicklistener () { Public void OnClick(Dialoginterface Dialog,intwhich) {Toast.maketext (mainactivity. This, Mitems[which], Toast.length_short). Show ();            }            }); Builder1.create (). Show (); Break; CaseR.id.btn3:progressdialog Mprogressdialog =NewProgressDialog (mainactivity. This);            Mprogressdialog.seticon (R.drawable.ic_launcher); Mprogressdialog.settitle ("First progress bar box");//Set progress bar styleMprogressdialog.setprogressstyle (progressdialog.style_horizontal);//Set the maximum value of the progress barMprogressdialog.setmax ( the); Mprogressdialog.setbutton ("Confirm",NewDialoginterface.onclicklistener () { Public void OnClick(Dialoginterface arg0,intARG1) {Toast.maketext (mainactivity. This,"clicked-Confirm", Toast.length_short). Show ();            }            }); Mprogressdialog.setbutton ("Cancel",NewDialoginterface.onclicklistener () { Public void OnClick(Dialoginterface arg0,intARG1) {Toast.maketext (mainactivity. This,"Clicked--Cancel", Toast.length_short). Show ();            }            }); Mprogressdialog.show (); Break; CaseR.id.btn4:mprogressdialog =NewProgressDialog ( This); Mprogressdialog.settitle ("Second progress bar Box"); Mprogressdialog.setmessage ("Reading, please wait ..." "); Mprogressdialog.setindeterminate (true); Mprogressdialog.setcancelable (true); Mprogressdialog.show (); Break; }    }   }

Operation Result:

Click the first button:

Click the second button:

Click a third button:

Click the fourth button:

Focus on technology, enjoy life! --qq:804212028
Browse Links: http://blog.csdn.net/y18334702058/article/details/44624305

Step by Step _android Development Course [18]_ User Interface Dialog (dialog box)

Related Article

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.