AlertDialog setSingleChoice without switches

I use alertDialog to display counter-like data. Is there a way to move the active selection (e.g. to setSingleChoice) using setItems?

I want the displayed list to look like a counter, without radio buttons.

+3
source share
1 answer

Browse this page from the Android API. You can create a list of items to display. The length of the array can be as long as you want. The list will scroll when the number of items becomes large enough. Very similar to a spinner.

final CharSequence[] items = {"Red", "Green", "Blue"};

AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("Pick a color");
builder.setItems(items, new DialogInterface.OnClickListener() {
    public void onClick(DialogInterface dialog, int item) {
        Toast.makeText(getApplicationContext(), items[item], Toast.LENGTH_SHORT).show();
    }
});
AlertDialog alert = builder.create();
+1
source

Source: https://habr.com/ru/post/1772310/


All Articles