Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to popup list like a spinner without spinner in android?

I have a spinner widget in my activity which lets users pick a list name.

Normally, the function of the spinner is to switch between lists but for a couple of instances, I swap out the selection change listener to perform a different function with the same list of options. Once the selection has been made, the old listener is restored and life goes on.

This is a bad and buggy arrangement. Instead, I would like to have a function that just takes a selection listener and some other parameters and shows a popup list that's populated by the same cursor (or and identical cursor) as the spinner, without using the spinner itself.

Is there any way I can do this?

like image 482
CodeFusionMobile Avatar asked Jan 25 '10 01:01

CodeFusionMobile


People also ask

How can I make my spinner look like Edittext?

simple_spinner_dropdown_item is used for dropdown item and custom layout custom_spinner_item is used for spinner view to show only TextView . FYI, You can customize this TextView as per your needs.

How can I tell if spinner is clicked or not in android?

Let the Spinner's first value be something like "-please select-". when the user clicks on the next button perform validation and check whether the value of the selectedItem in the spinner is "-please select-" and if yes, then display a toast and ask the the user to select something from the spinner.

What is spinner in Android with example?

Spinners provide a quick way to select one value from a set. In the default state, a spinner shows its currently selected value. Touching the spinner displays a dropdown menu with all other available values, from which the user can select a new one.


2 Answers

This is best example for popup details like spinner using AlertDialog and AlertDialog.Builder

        AlertDialog dialog;

         final CharSequence[] items = { "Item1", "Item2" };
        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setTitle(title);
        builder.setItems(items, new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int pos) {
            switch (pos) {
                case 0:
                              {
        Toast.makeText(this,"Clicked on:"+items[pos],Toast.LENGTH_SHORT).show();

                      }break;
            case 1:
                              {
        Toast.makeText(this,"Clicked on:"+items[pos],Toast.LENGTH_SHORT).show();

                      }break;
        }
    }});
dialog=builder.create();
dialog.show();
like image 176
Ramesh Akula Avatar answered Nov 15 '22 06:11

Ramesh Akula


Use AlertDialog.Builder and supply an Adapter via setAdapter() that generates your rows.

In your case, I would not use the same Cursor, as a Cursor has an intrinsic notion of the current row, and so messing with the Cursor while it is used by your SpinnerAdapter could screw up the Spinner. Go with an identical Cursor.

like image 43
CommonsWare Avatar answered Nov 15 '22 06:11

CommonsWare