Spinner

Hi Guys!!

Today I am sharing the code about the Spinner in android.
Spinners provide a quick way to select one value from a set. In the default state, a spinner shows its currently selected value. Touching the spinner displays a dropdown menu with all other available values, from which the user can select a new one.
For detail please visit android developer site Spinner.

So lets start the coding about the spinner in android.

activity_main.xml



    

    



MainActivity.java

package com.sunil.spinner;

 import android.app.Activity;
import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.Spinner;
 
public class MainActivity extends Activity {
  
 private static final String[] dayOfWeek =
  {"Sunday", "Monday", "Tuesday", "Wednesday",
   "Thursday", "Friday", "Saturday"};
  private ArrayAdapter adapter;
  
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        Spinner spinner = (Spinner)findViewById(R.id.spinner);
         
        adapter = new ArrayAdapter(this, android.R.layout.simple_spinner_item, dayOfWeek);
        adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
        spinner.setAdapter(adapter);
    }
}

 You can download the source code Spinner. 

Cheers Guys!!

2 comments:

Debug Database in Android

In my last tutorial, we have learned how we can use persistence database in android. We also understood which database wrapper we can use...

Contact Me

Name

Email *

Message *