Thursday 15 November 2012

Steps to design Spinner in Android ?


Spinner View
Steps:
1.Create the xml file with Spinner
Ex:
<Spinner
        android:id="@+id/spinner"
        android:layout_width="50dp"
        android:layout_height="20dp" />

2.Get the reference of Spinner to the Acivity.
Ex:
Spinner spinner = (Spinner) findViewById(R.id.spinner);

3.Create the String array with the suggestion values.
Ex:
String[] languages = { "Android", "Java", "xml", "Dot Net", "c", "Cpp","Oracle"};

4.Create the ArrayAdapter object for holding the suggestion Values.
Ex:
ArrayAdapter adapter = new ArrayAdapter(getApplicationContext(),
android.R.layout.simple_list_item_1, languages);

5.Attach the ArrayAdapter object to Spinner.
Ex:
spinner.setAdapter(adapter);

No comments:

Post a Comment