Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Alert dialog with text followed with a checkbox and 2 buttons

Tags:

android

I have requirement to pop up alert dialog which is like a EULA screen. Which will have text describing EULA with a checkbox "Don't show this again" and in the end 2 buttons for OK and Cancel.

How to have textview and checkbox as part of alert dialog?

like image 942
Manju Avatar asked Feb 11 '11 03:02

Manju


1 Answers

I have to agree with Mudassir, EULAs are not suppose to have "Don't show again" checkboxes, but here's how you could go about doing something like that though.

You can use a AlertDialog.Builder to build a dialog box that contains a view (which you can design in XML). Here's an example

AlertDialog.Builder eulaBuilder = new AlertDialog.Builder(this);
            LayoutInflater eulaInflater = LayoutInflater.from(this);
            View eulaLayout = eulaInflater.inflate(R.layout.eula, null);
            eulaBuilder.setView(eulaLayout);
            Checkbox dontShowAgain = (CheckBox)eulaLayout.findViewById(R.id.dontShowAgain);
            eulaBuilder.setPositiveButton("Agree", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface d, int m) {
                    // Do something
                }
            });        
            eulaBuilder.setNegativeButton("Disagree", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface d, int m) {
                    // Do something
                }
            });
            eulaMsg = eulaBuilder.create();

What you can do is create an XML with a single object, CheckBox. Then add the view into the AlertDialog.Builder. Use AlertDialog.Builder.setMessage("EULA message here") to set your EULA message.

like image 105
Brian Avatar answered Nov 15 '22 23:11

Brian