Is there a way to add a summary or a additional text to a alertDialog with single choice items? I'd like to have a bold header and a small text with some extra informations.
Asked
Active
Viewed 2,461 times
3 Answers
8
Google says:
"Because the list appears in the dialog's content area, the dialog cannot show both a message and a list": http://developer.android.com/guide/topics/ui/dialogs.html
It seems that buttons, message and multiple choice items are exclusive. If you want to have both message and multiple choice item, you'll have to do something custom with your own DialogFragment

Anne-Claire
- 872
- 8
- 16
-3
set the title and then the message:
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(
context);
// set title
alertDialogBuilder.setTitle("Your Title");
// set dialog message
alertDialogBuilder
.setMessage("Click yes to exit!")
.setCancelable(false)
.setPositiveButton("Yes",new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,int id) {
// if this button is clicked, close
// current activity
MainActivity.this.finish();
}
})
.setNegativeButton("No",new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,int id) {
// if this button is clicked, just close
// the dialog box and do nothing
dialog.cancel();
}
});
// create alert dialog
AlertDialog alertDialog = alertDialogBuilder.create();
// show it
alertDialog.show();
}

erik
- 4,946
- 13
- 70
- 120
-
2..and where are now the single choice items requested in the question? – Bachi Sep 14 '15 at 12:27
-3
You can use in built method setSingleChoiceItems
of AlertDialog -
final CharSequence[] items = {"Red", "Green", "Blue"};
AlertDialog dialog = new AlertDialog.Builder(this).setMessage("Hello world").show();
TextView textView = (TextView) dialog.findViewById(android.R.id.message);
textView.setTextSize(10); //small text font
dialog.setTitle("Colors");
dialog.setSingleChoiceItems(items, -1, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int item) {
Toast.makeText(getApplicationContext(),
items[item], Toast.LENGTH_SHORT).show();
}
});

sjain
- 23,126
- 28
- 107
- 185
-
1.. and where is the text on the AlertDialog the question asks for? I think this is all about having BOTH single choice items and message text in a standard AlertDialog (probably not possible without custom view) – Bachi Sep 14 '15 at 12:29