Spinners in Android

Posted by Unknown Kamis, 24 Januari 2013 0 komentar
The Android Spinner Control is definitely the equivalent of the drop-down selector . By making use of spinner control you basically obtain the capability to choose from a list without taking up all of the display screen space of a ListView.

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.

You can add a spinner to your layout with the Spinner object. You should usually do so in your xml layout with a  <spinner>  element.
For example:
 <Spinner
   
        android:id="@+id/myspinner"   
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" />

Here we go with java source code:
in java file:
 
public class simplespinnersactivity extends Activity implements OnItemSelectedListener {
TextView selection;
String[] items = { "this", "is", "a","really","a" "simple","list", "in", "android", "ok" };

@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
selection = (TextView) findViewById(R.id.selection);
Spinner spin = (Spinner) findViewById(R.id.spinner);
spin.setOnItemSelectedListener(this);
ArrayAdapter aa = new ArrayAdapter(this,android.R.layout.simple_spinner_item,items);
aa.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spin.setAdapter(aa);
}
public void onItemSelected(AdapterView parent, View v,int position,long id)
{
selection.setText(items[position]);
}
public void onNothingSelected(AdapterView parent)
{
selection.setText("");
}
}

in xml file:
<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:id="@+id/selection"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello"/>

<Spinner
android:id="@+id/spinner"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:drawSelectorOnTop = "true">

</Spinner>
</LinearLayout>
TERIMA KASIH ATAS KUNJUNGAN SAUDARA
Judul: Spinners in Android
Ditulis oleh Unknown
Rating Blog 5 dari 5
Semoga artikel ini bermanfaat bagi saudara. Jika ingin mengutip, baik itu sebagian atau keseluruhan dari isi artikel ini harap menyertakan link dofollow ke http://androidpopuler.blogspot.com/2013/01/spinners-in-android.html. Terima kasih sudah singgah membaca artikel ini.

0 komentar:

Posting Komentar

Trik SEO Terbaru support Online Shop Baju Wanita - Original design by Bamz | Copyright of android populer.