How to stack AlertDialog buttons vertically?
You can't do that with an AlertDialog
. You should create a custom Dialog
, and implement that yourself. Something like this would do it
Dialog dialog = new Dialog(context);
dialog.setContentView(R.layout.dialog_layout);
dialog.setTitle(...);
dialog.setMessage(...);
dialog.show();
and your layout dialog_layout.xml
should be something like
<LinearLayout android:layout_width="match_parent"
android:layout_height="wrap_content"
orientation="vertical">
<Button android:layout_width="wrap_content" android:layout_height="wrap_content"/>
<Button android:layout_width="wrap_content" android:layout_height="wrap_content"/>
<Button android:layout_width="wrap_content" android:layout_height="wrap_content"/>
</LinearLayout>
What if you did the alert box as a list?
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
builder.setTitle(R.string.pick_color)
.setItems(R.array.colors_array, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
// The 'which' argument contains the index position
// of the selected item
}
});
return builder.create();
}
Example taken from here (under adding a list): https://developer.android.com/guide/topics/ui/dialogs.html
Then just take those list options and turn them into what you want.