dialog box Android

Source: Internet
Author: User

 Public void Click1(View view) {/**/Creator of Dialog box * * Alertdialog.builder builder =NewBuilder ( This); Builder.settitle ("I am a dialog box"); Builder.setmessage (The dialog box displays the contents of the);/////***********************************************************Builder.setpositivebutton ("Dsad",NewOnclicklistener () {@Override Public void OnClick(Dialoginterface Dialog,intwhich) {//TODO auto-generated method stub}        }); Builder.setpositivebutton ("OK",NewOnclicklistener () {@Override Public void OnClick(Dialoginterface Dialog,intwhich) {Toast.maketext (), Getapplicationcontext (),"OK was clicked",0). Show ();        }        }); Builder.setnegativebutton ("Cancel",NewOnclicklistener () {@Override Public void OnClick(Dialoginterface Dialog,intwhich) {//Don't write anything the default implementation is to close the dialog box}        });/////**************************************************************Builder.setcancelable (false);//dialog can not be canceled, only select the optionBuilder.show ();//builder.create (). Show ();}
/** *** 单选对话框** * @param view */
 Public void Click2(View view) {//The creator of the dialog boxAlertdialog.builder Builder =NewBuilder ( This); Builder.settitle ("Please select your gender");Finalstring[] items = {"Male","female","Unknown"}; Builder.setsinglechoiceitems (Items,2,NewOnclicklistener () {@Override             Public void OnClick(Dialoginterface Dialog,intwhich) {Toast.maketext (), Getapplicationcontext (),"Your Gender:"+items[which],0). Show ();            Dialog.dismiss ();        }        }); Builder.show ();//equivalent to builder. Creat (). Show ();}
/** * **多选对话框** * @param view */
 Public void Click3(View view) {//The creator of the dialog boxAlertdialog.builder Builder =NewBuilder ( This); Builder.settitle ("Please choose your favorite fruit");FinalString[] items={"Apple","Pear","Pineapple","Banana","Cucumber"};Final Boolean[] result =New Boolean[]{true,false,true,false,false}; Builder.setmultichoiceitems (items, result,NewOnmultichoiceclicklistener () {@Override             Public void OnClick(Dialoginterface Dialog,intWhich,BooleanisChecked) {Toast.maketext (Getapplicationcontext (), items[which]+ischecked,0). Show ();            Result[which] = isChecked;        }        }); Builder.setpositivebutton ("Submit",NewOnclicklistener () {@Override             Public void OnClick(Dialoginterface Dialog,intwhich) {StringBuffer SB =NewStringBuffer (); for(intI=0; i<result.length;i++) {if(Result[i]) {Sb.append (items[i]+","); }} toast.maketext (Getapplicationcontext (),"You have selected,"+sb.tostring (),0). Show (); }        });//builder.create (). Show ();Builder.show ();//equivalent to builder. Creat (). Show ();}
**//进度条对话框**
    publicvoidclick4(View view){        new ProgressDialog(this);        pd.setTitle("提醒");        pd.setMessage("正在加载数据...请稍等。");        pd.show();    }
**//带进度的进度条对话框**
 Public void Click5(View view) {FinalProgressDialog PD =NewProgressDialog ( This); Pd.settitle ("Reminders");        Pd.setprogressstyle (progressdialog.style_horizontal); Pd.setmax ( -); Pd.setmessage ("Loading Data ... Please wait a moment. "); Pd.show ();NewThread () { Public void Run() { for(inti =0;i< -; i++) {Try{Thread.Sleep ( +); }Catch(Exception e)                    {E.printstacktrace ();                } pd.setprogress (i);            } Pd.dismiss ();        };    }.start (); }

dialog box Android

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.