Spinner in Android

spinner in android is used to give user to choose an option from drop down list which contains the options...and when you choose any option it will display that option..by default it will display first option...



public class main extends Activity {
    /** Called when the activity is first created. */
 String [] name = {"ram","shayam","reeta","geeta","seeta"};
Context ctx;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        ctx =this;

     
Spinner spin = (Spinner)findViewById(R.id.spinner1);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(ctx,android.R.layout.simple_spinner_item,name);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spin.setAdapter(adapter);
       
       
    }
}

Comments

Popular Posts