Android UI Design Alertdialog window control _android

Source: Internet
Author: User
Tags set time

I think we've seen a lot of Android's window interface, mobile phone many applications are involved in the window controls, such as a typical delete a picture each time or uninstall a will pop up a window to ask whether delete/uninstall, as well as our system set time/date, etc., have used such controls, Below I will summarize the common several window controls by the code

Activity_main.xml

<?xml version= "1.0" encoding= "Utf-8"?> <linearlayout xmlns:android= "http://schemas.android.com/apk/res/" Android "xmlns:tools=" Http://schemas.android.com/tools "android:layout_width=" Match_parent "android:layout_height = "Match_parent" android:orientation= "vertical" tools:context= "com.company.alertdialog.MainActivity" > < Button android:id= "@+id/btn1" android:layout_width= "wrap_content" android:layout_height= "Wrap_content" and roid:onclick= "OnClick" android:text= "list Pinball window"/> <button android:id= "@+id/btn2" android:layout_width= "WR" Ap_content "android:layout_height=" wrap_content "android:onclick=" OnClick "android:text=" "Radio bomb window"/> <Bu Tton android:id= "@+id/btn3" android:layout_width= "wrap_content" android:layout_height= "Wrap_content" Andro id:onclick= "OnClick" android:text= "Multiple selection of window"/> <button android:id= "@+id/btn4" android:layout_width= _content "android:layout_height=" Wrap_cOntent "android:onclick=" OnClick "android:text=" date Pinball window "/> <button android:id=" @+id/btn5 "android:l Ayout_width= "Wrap_content" android:layout_height= "wrap_content" android:onclick= "OnClick" android:text= "Time Bomb window" /> <button android:id= "@+id/btn6 android:layout_width=" wrap_content "android:layout_height=" Wrap_con

 Tent "android:onclick=" OnClick "android:text=" progress bar window "/> </LinearLayout>

Strings.xml

<resources>
  <string name= "app_name" >AlertDialog</string>
  <string-array name= "list" >
    <item> list one </item>
    <item> list two </item>
    <item> list three </item>
    <item> list four </item>
    <item> list five </item>
    <item> list six </item>
  </ String-array>
</resources>

Mainactivity.java

public class Mainactivity extends Appcompatactivity implements View.onclicklistener {//= List window private Button mBtn1;

  The Radio bomb window private Button mBtn2;

  The multiple-selection bullet window private Button mBtn3;

  Indicates the Date Pinball window private Button mBtn4;

  Indicates that the time Bomb window private Button mBtn5;

  Represents the progress bar window private Button mBtn6;
    @Override protected void OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate);
    Setcontentview (R.layout.activity_main);
    Init ();
  Event ();
    /** * Set listener Event/private void event () {Mbtn1.setonclicklistener (this);
    Mbtn2.setonclicklistener (this);
    Mbtn3.setonclicklistener (this);
    Mbtn4.setonclicklistener (this);
    Mbtn5.setonclicklistener (this);
  Mbtn6.setonclicklistener (this);
    /** * Initialization control/private void init () {mBtn1 = (Button) Findviewbyid (R.ID.BTN1);
    MBTN2 = (Button) Findviewbyid (R.ID.BTN2);
    MBtn3 = (Button) Findviewbyid (R.ID.BTN3);
    MBtn4 = (Button) Findviewbyid (R.ID.BTN4); MBtn5 = (Button) Findviewbyid (R.ID.BTN5);
  MBtn6 = (Button) Findviewbyid (R.ID.BTN6);
        @Override public void OnClick (View v) {switch (V.getid ()) {case R.id.btn1:createlistdialog ();
      Break
        Case R.id.btn2:createsingledialog ();
      Break
        Case R.id.btn3:createmutildialog ();
      Break
        Case R.id.btn4:createdatedialog ();
      Break
        Case R.id.btn5:createtimedialog ();
      Break
        Case R.id.btn6:createprogressbardialog ();


    Break }/** * Create a progress bar window/private void Createprogressbardialog () {//Create progress bar Window object ProgressDialog PROGRESSDI
    Alog = new ProgressDialog (this);
    Set the title Progressdialog.settitle ("Progress bar Window");
    Set the title icon Progressdialog.seticon (R.mipmap.ic_launcher);
    Set text Progressdialog.setmessage ("Loading ...");
    Set maximum Progress Progressdialog.setmax (100); Sets the type of the progress bar Progressdialog.setprogressstyle (Progressdialog.style_horiZontal);
    Show progress bar window Progressdialog.show (); If you set this statement, no matter if you click anywhere outside the screen or press the return key to cancel the window,//unless the progress is completed, set the cancellation event. Generally, this setting is very unfriendly to the interface. However, sometimes the software has a major bug, the user has to update the software, if not updated, only//forced to quit the program//progressdialog.setcancelable (FALSE);
  Some ways to cancel, such as by the area outside the dialog box or the Return key progressdialog.setprogress (50); /** * Create a Date pinball window/private void Createdatedialog () {New Datepickerdialog (this, new Datepickerdialog.ondat Esetlistener () {/** * * @param view current date selected View * @param year current selection * @param monthofy The current month selected by the ear, starting from 0 * @param dayofmonth, the currently selected day, starting at 1, is the * * @Override public void Ondateset (DatePicker View, int year, int monthofyear, int dayofmonth) {toast.maketext (mainactivity.this, "view =" + View + "years:" + yea
      R + "Month:" + monthofyear + "Day" + DayOfMonth, Toast.length_short). Show (); }, 2016, 7, 15)//Here It is noted that the month system is the beginning of the 0, 0 means January, 1 means February ...
  11 Expression December. Show (); /** * Create a time bomb window * * private void CReatetimedialog () {New Timepickerdialog (this, new Timepickerdialog.ontimesetlistener () {/** * *  @param view Current time selected View * @param hourofday hours * @param minute minutes/@Override public void  Ontimeset (timepicker view, int hourofday, int minute) {Toast.maketext (mainactivity.this, "time bomb window view =" + View +
      "Hourofday =" + Hourofday + "minute =" + Minute, Toast.length_short). Show ();
  }, one, true. Show (); /** * Create a multiple-selection pinball window/private void Createmutildialog () {new Alertdialog.builder (this). Settitle ("Multiple selection Frame "). SetIcon (R.mipmap.ic_launcher)//second argument Boolean array, if write null represents default all unchecked, if you want to specify a few selected,//need to create a corresponding length  Degrees, set the specified position to true in order of position, the length of the array cannot be small//to the length of the data source, or it may be out of bounds, but can be greater than the length of the data source. Setmultichoiceitems (R.array.list, new Boolean[]{true, False, False, True, False, False, False, False, False, False, false, new DIALOGINTERFACE.O NmultichoiceclicklisteNER () {/** * * * @param dialog the currently clicked dialog box * @param which the currently clicked entry * @par  Am ischecked is clicked on the entry's selected state */@Override public void OnClick (Dialoginterface dialog, int which, Boolean ischecked) {Toast.maketext (Mainactivity.this, "The current click is" + which + "is selected" + ischecked, toast.length_s
          Hort). Show ();
          })//Set the Cancel button and set the Listener event. Setnegativebutton ("Cancel", new Dialoginterface.onclicklistener () {
          @Override public void OnClick (Dialoginterface dialog, int which) {Dialog.dismiss ();
          })//Confirm button, the default click will cancel the window directly. Setpositivebutton ("Sure", new Dialoginterface.onclicklistener () { @Override public void OnClick (Dialoginterface dialog, int which) {}}). setcance
  Lable (False). Show (); /** * Create a single Window/private void Createsingledialog () {New Alertdialog.buIlder (This). Settitle ("Radio Bomb Window"). SetIcon (R.mipmap.ic_launcher)//construction parameters, 1 data sources, 2 default selected index, 3 object Click event
           . Setsinglechoiceitems (R.array.list, 1, New Dialoginterface.onclicklistener () {/** * * @param dialog Current dialog box * @param which is currently clicking on the first few item of the list * * @Override public Voi D-OnClick (dialoginterface dialog, int which) {Toast.maketext (mainactivity.this, "Radio Bomb window Dialog =" + Dialog + "
          which = "+ which, Toast.length_short). Show (); }). Setnegativebutton ("Cancel", new Dialoginterface.onclicklistener () {@Override PU
          Blic void OnClick (dialoginterface dialog, int which) {Dialog.dismiss (); }). Setpositivebutton ("Sure", new Dialoginterface.onclicklistener () {@Override Publ IC void OnClick (Dialoginterface dialog, int which) {}}). Setcancelable (FALSE)//not allowed to be in some wayCancel, such as by pressing the area outside the dialog box or by returning the key. Show (); /** * Create a list bomb window/private void Createlistdialog () {Alertdialog.builder Builder = new Alertdialog.builde
    R (this);
    Builder.settitle ("List Bomb window");
       Builder.setitems (R.array.list, New Dialoginterface.onclicklistener () {/** * * @param Dialog Current dialog box * @param which is currently clicking on the first few item of the list * * @Override public void OnClick (dialoginterface dialog, int whic
      h) {Toast.maketext (mainactivity.this, "list dialog =" + Dialog + "which =" + which, Toast.length_short). Show ();
    }
    });
  Builder.setcancelable (false);//not allowed to be canceled in some way, such as by the area outside the dialog box or the Return key builder.show ();

 }
}

List Play window:

Radio Bomb window:

Multi-Selection window:

Date Pinball window:

Time Bomb window:

Progress bar window:

Some of the most common are here, as there is a popupwindow here for the time being not introduced.

The above is the entire content of this article, I hope to help you learn, but also hope that we support the cloud habitat community.

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.