1

I'm trying to create an AlertDialog where both a message (in a TextView, for instance) and a MultiChoice-list can be displayed at the same time, but I'm a bit lost as to how to do it.

Will I have to create my own subclass of AlertDialog, or is there an easier way to do it?

Cethy
  • 551
  • 6
  • 18
  • You don't have to subclass AlertDialog. You can set the message using Builder.setMessage("Your message"). And for the multi-choice list you can refer the following link http://www.101apps.co.za/index.php/articles/making-a-list-coding-multiple-choice-list-dialogs.html – Rahul Chaurasia Nov 10 '15 at 16:48
  • I believe this has been answered here --> http://stackoverflow.com/questions/15762905/how-can-i-display-a-list-view-in-an-android-alert-dialog Hope it helps – Rafael Nunes Nov 10 '15 at 16:51

2 Answers2

0

You could create a normal AlertDialog but, instead of using the setMessage() method, you could just use a custom layout (you can inflate it in a View or even create a custom view) and use then the setView() method of the AlertDialog class.

tiwiz
  • 327
  • 5
  • 19
  • But if I used a custom layout - would I still be able to call "setMultiChoiceItems" in the AlertDialog? – Cethy Nov 10 '15 at 16:51
  • 1
    If you use a custom layout, you would not need to use it, but you can defer the logic elsewhere, but @iatsenko-anton answer would make your life much easier, I would say :-) – tiwiz Nov 10 '15 at 16:53
0

Use DialogFragment for customization

    public class ResponseDialog extends DialogFragment implements View.OnClickListener{

    @Override
    public void onActivityCreated(Bundle arg0) {
        super.onActivityCreated(arg0);
        getDialog().getWindow()
                .getAttributes().windowAnimations = R.style.DialogAnimationFromDown;
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setStyle(DialogFragment.STYLE_NO_TITLE, android.R.style.Theme_Black_NoTitleBar);
    }

    @Override
    public Dialog onCreateDialog(Bundle savedInstanceState) {
        Dialog dialog = super.onCreateDialog(savedInstanceState);
        dialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
        return dialog;
    }

    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View v = inflater.inflate(R.layout.YOUR_CUSTOM_LAYOUT, null);
        //implement in layout what you want 
        return v;
    }

    public void onDismiss(DialogInterface dialog) {
        super.onDismiss(dialog);
    }

    public void onCancel(DialogInterface dialog) {
        super.onCancel(dialog);
    }
    }
}

for more info https://developer.android.com/reference/android/app/DialogFragment.html

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
Iatsenko Anton
  • 157
  • 1
  • 6