Code example for Spinner

Methods: setAdapter, setOnItemSelectedListener

0
        Spinner mSpinner = new Spinner(activity);
        mSpinner.setAdapter(new ArrayAdapter<String>(activity, android.R.layout.simple_spinner_item, items));
 
        mSpinner.setOnItemSelectedListener(new OnItemSelectedListener() {
            public void onItemSelected(AdapterView<?> adapter, View view, int position, long id) {
                mSelected = position;
            } 
 
            public void onNothingSelected(AdapterView<?> arg0) {
            } 
        }); 
 
        this.setTitle(title);
        this.setMessage(message);
        this.setView(mSpinner);
 
        this.setButton("Ok", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int id) {
                listener.onItemSelected(mSelected);
            } 
Contextual code suggestions in your IDE  Get Codota for Java