Android Spinner

Spinner spinner = findViewById(;

// Create an ArrayAdapter using the String array and a spinner layout
ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this,
        R.array.spinner_values, R.layout.spinner_item);

// Specify the layout to use when the list of choices appears

// Apply the adapter to the spinner

spinner.setOnItemSelectedListener(new OnItemSelectedListener() {
    public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
        Log.d("Spinner Demo", "" + parent.getItemAtPosition(position));

    public void onNothingSelected(AdapterView<?> parent) {
        Log.d("Spinner Demo", "Nothing selected");