Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AlertDialog setSingleChoice without radio buttons

I am using an alertDialog to display data similar to a spinner. Is there a way to move the active selection (like in setSingleChoice) using setItems ?

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

like image 482
miannelle Avatar asked Oct 31 '10 01:10

miannelle


People also ask

Can you have an alert dialog without any buttons if not why?

You can do this very easily. AlertDialog. Builder alertDialogBuilder = new AlertDialog. Builder(context); // set title alertDialogBuilder.

Is AlertDialog deprecated?

Is AlertDialog deprecated? This method is deprecated.

How many buttons can be set up on an AlertDialog?

AlertDialog. A dialog that can show a title, up to three buttons, a list of selectable items, or a custom layout.

What is the difference between Dialog and AlertDialog?

AlertDialog is a lightweight version of a Dialog. This is supposed to deal with INFORMATIVE matters only, That's the reason why complex interactions with the user are limited. Dialog on the other hand is able to do even more complex things .


1 Answers

Check out this page from the Android API. You can create a list of items to display. The array length can be as long as you want. The list will scroll when the number of items gets big enough. Very much like 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();
like image 141
Jake Wilson Avatar answered Sep 18 '22 20:09

Jake Wilson