android dialog box

Source: Internet
Author: User

Project Source Download

Https://github.com/Wang-Jun-Chao/AndroidProjects

dialog box

OK Cancel dialog box

Create a Dialog Builder object, similar to Factory mode

        Alertdialog.builder Builder =  Builder ();

Set the title and body

        Builder ()
        Builder ()

Set OK and Cancel buttons

        Builder.setpositivebutton (,  Onclicklistener () {

            
              (Dialoginterface dialog,  which) {
                
                Toast.maketext (mainactivity.,,). Show ();
            }
        );

        Builder.setnegativebutton (,  Onclicklistener () {

            
              (Dialoginterface dialog,  which) {
                
                Toast.maketext (mainactivity.,,). Show ();
            }
        );

To create a dialog object using the Builder

        Alertdialog ad = Builder. ();
        Ad. ();

Radio dialog box

        Alertdialog.builder Builder =  Builder ();
        Builder.settitle ();

Define a single selection option

         string[] items =  string[]{
                ,, 
        };
        
        
        Builder.setsinglechoiceitems (items,-,  Onclicklistener () {

            
            
              (Dialoginterface dialog,  which) {
                Toast.maketext (mainactivity.,  + Items[which],). Show ();
                
                Dialog.dismiss ();
            }
        );

        Builder.show ();

Multi-selection dialog box

        Alertdialog.builder Builder =  Builder ();
        Builder.settitle ();

Define multiple selections because you can select more than one, so you need a Boolean array to record which options are selected

 string[] items = string[]{,,,
        
         };
        [] CheckedItems = []{,,,,};

            
            
              Builder.setmultichoiceitems (items, CheckedItems, Onmultichoiceclicklistener () { (Dialoginterface dialog, which, ischecked)
            {Checkeditems[which] = ischecked;

        }
        });
                Builder.setpositivebutton (, Onclicklistener () {(Dialoginterface dialog, which) {
                StringBuffer sb = StringBuffer (); (i =; i < items.length; i++)
                {sb.append (checkeditems[i]? Items[i] +:);
            } toast.maketext (mainactivity., sb.tostring (),). Show ();
        }
        }); Builder.show (); 

More Wonderful content: http://www.bianceng.cnhttp://www.bianceng.cn/OS/extra/

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.