Summary Notes for various android dialogs

Source: Internet
Author: User

Summary Notes for various android dialogs
Confirm cancel dialog box (with ICON)

// (Context, topic) new AlertDialog. builder (this, AlertDialog. THEME_DEVICE_DEFAULT_LIGHT ). setTitle ). setMessage (content ). setIcon (R. drawable. ic_launcher) // responds to the click event. setPositiveButton (OK, new OnClickListener () {@ Override public void onClick (DialogInterface dialog, int which) {// TODO Auto-generated method stub Toast. makeText (MainActivity. this, OK, 0 ). show ();}}). setNegativeButton (cancel, null ). show (); // do not forget to show
Effect


Simple radio dialog box
Final String [] strs = new String [] {male, female, don't tell you}; new AlertDialog. builder (this, AlertDialog. THEME_DEVICE_DEFAULT_LIGHT ). setTitle ). setIcon (R. drawable. ic_launcher) // (String array, default option, RESPONSE event ). setSingleChoiceItems (strs, 2, new OnClickListener () {// swich: array id of the selected option @ Overridepublic void onClick (DialogInterface dialog, int which) {// TODO Auto-generated method stubToast. makeText (MainActivity. this, strs [which], 0 ). show ();}}). show ();
Effect

Multiple choice dialog box
Final String [] strs = new String [] {bananas, apples, pears}; AlertDialog. builder dialog = new AlertDialog. builder (this, AlertDialog. THEME_DEVICE_DEFAULT_LIGHT ). setTitle ). setIcon (R. drawable. ic_launcher ). setMultiChoiceItems (strs, new boolean [] {true, true, false}, new OnMultiChoiceClickListener () {// which: The selected array id // isChecked: selected status @ Override public void onClick (DialogInterface dialog, int which, boolean isChecked) {// TODO Auto-generated method stub Log. d (test, which = + which +: isChecked = + isChecked) ;}}); dialog. create (). show ();
Effect


Progress dialog box
ProgressDialog pd = new ProgressDialog (this); pd. setTitle (title); pd. setMessage (please bring it to...); pd. show ();


Progress bar dialog box
Final ProgressDialog pd = new ProgressDialog (this); // there are only two types of topic pd. setProgressStyle (ProgressDialog. STYLE_HORIZONTAL); // sets the maximum progress value of pd. setMax (1, 100); pd. setTitle (title); pd. setMessage (please include .....); pd. show (); new Thread () {public void run () {for (int I = 1; I <100; I ++) {try {Thread. sleep (100);} catch (InterruptedException e) {// TODO Auto-generated catch block e. printStackTrace ();} pd. setProgress (I);} // can be disabled in any thread, pd. dismiss ();};}. start ();
Effect
Custom dialog box
Final EditText et_text = new EditText (this); new AlertDialog. builder (this ). setTitle (enter) // enter a TextView. setIcon (android. r. drawable. ic_dialog_info ). setView (et_text ). setPositiveButton (OK, new OnClickListener () {@ Override public void onClick (DialogInterface dialog, int which) {// TODO Auto-generated method stub Toast. makeText (MainActivity. this, et_text.getText (). toString (), 0 ). show ();}}). setNegativeButton (cancel, null ). show ();

Effect

 
     
 

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.