Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android- How to use Spinner in an AlertDialog?

I have a spinner, how can i bind it to an AlertDialog? It is possible to do that?

like image 921
detno29 Avatar asked Feb 06 '12 09:02

detno29


People also ask

How do you make a clickable spinner?

Try removing the xml attribute android:clickable="true" from the Spinner widget. It could be that the entire spinner is registering the click event rather than the individual spinner items.

Is AlertDialog deprecated?

This constant was deprecated in API level 23.

Which method is used to set in AlertDialog?

Alert Dialog code has three methods: setTitle() method for displaying the Alert Dialog box Title. setMessage() method for displaying the message. setIcon() method is use to set the icon on Alert dialog box.

How many button options can you use in creating AlertDialog?

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


1 Answers

please try this :

 public class WvActivity extends Activity {

TextView tx;
String[] s = { "India ", "Arica", "India ", "Arica", "India ", "Arica",
        "India ", "Arica", "India ", "Arica" };
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    final ArrayAdapter<String> adp = new ArrayAdapter<String>(WvActivity.this,
            android.R.layout.simple_spinner_item, s);

    tx= (TextView)findViewById(R.id.txt1);
    final Spinner sp = new Spinner(WvActivity.this);
    sp.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT));
    sp.setAdapter(adp);

    AlertDialog.Builder builder = new AlertDialog.Builder(WvActivity.this);
    builder.setView(sp);
    builder.create().show();
  }
 }
like image 191
Ramesh Solanki Avatar answered Sep 28 '22 19:09

Ramesh Solanki