c0dehunter
c0dehunter

Reputation: 6140

Show (dynamically created) Spinner

I have a Spinner:

     Spinner country_list=new Spinner(this);
     ArrayAdapter<String> adapter= new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, countries);
     adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
     country_list.setAdapter(adapter);

Now I want to show it as popup for user to select. Do I need to use AlertDialog or is there even a simpler way?

/EDIT: Actually, what I want is not Spinner. I want to get a list of countries when user clicks a button and then he or she can select a country. So basically his is the "second part" of Spinner - where a list shows in a popup. Should I use ListView?

Upvotes: 0

Views: 1233

Answers (3)

c0dehunter
c0dehunter

Reputation: 6140

What I needed was

country_list.performClick()

to display spinner with a button click.

Upvotes: 3

user936414
user936414

Reputation: 7634

If you want the spinner itself to be in a pop up, you have to use a dialog.

LayoutParams params = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
    Dialog d = new Dialog(this);
    d.requestWindowFeature(Window.FEATURE_NO_TITLE);
    d.addContentView(country_list, params);
    d.show();

Upvotes: 1

Samir Mangroliya
Samir Mangroliya

Reputation: 40406

Now I want to show it as popup for user to select. Do I need to use AlertDialog or is there even a simpler way?

-spinner already show as a pop-up and you can get selected value no need use alertDialog.

See This Example

Upvotes: 1

Related Questions