1

I have an alertDialog with the following code :

AlertDialog.Builder b = new AlertDialog.Builder(Activity.this);
String[] types = getResources().getStringArray(R.array.text_spinner_NewClass_dayList);
b.setSingleChoiceItems(types, 2, (dialog, which) -> {
            textView.setText(types[which]);
            dialog.dismiss();
        }
);
b.show();

I want to show all radio buttons of items but it only shows the selected item.

enter image description here

Nima Khalili
  • 360
  • 4
  • 20

2 Answers2

1

Create a xml layout as you want. And inflat that layout to alert dialog through View.

AlertDialog.Builder b = new AlertDialog.Builder(Activity.this);

//Your customized layout
final View customLayout = getLayoutInflater().inflate(R.layout.custom, null);

b.setView(customLayout);

b.show();
charlie.7
  • 329
  • 3
  • 5
1

According to my tests you can achieve it with MaterialAlertDialogBuilder or AlertDialog.Builder by setting setSingleChoiceItems

...

private var selectedFruitsIndex: Int = 0
private val fruits = arrayOf("Apple", "Banana", "Coconut", "Orange")

    MaterialAlertDialogBuilder(this)
            .setTitle("List of Fruits")
            .setSingleChoiceItems(fruits, selectedFruitsIndex) { dialog_, which ->
                selectedFruitsIndex = which
                selectedFruits = fruits[which]
            }
            .setPositiveButton("Ok") { dialog, which ->
                Toast.makeText(this, "$selectedFruits Selected", Toast.LENGTH_SHORT)
                        .show()
            }
            .setNegativeButton("Cancel") { dialog, which ->
                dialog.dismiss()
            }
            .show()
Lucas B.
  • 489
  • 5
  • 15