Friday, 6 September 2013

Android Drop Down List or Spinner Example

Android Drop Down List Android Drop Down List
  1. In this tutorial we show you simple spinner example which allow user to select an item from Drop Down list.
  2. In Spinner display static three image data selection after selecting image name picture1,picture2,picture3 effect on ImageView disply below Spinner or Drop Down list.
  3. In Android use android.widget.Spinner class for Drop Down selection list.
  4. Follow below steps for Android Spinner integration
  1. Create new Android Project and fill all require details.
  2. Open String.xml file under resources folder and modify as below.
     <?xml version="1.0" encoding="utf-8"?>  
     <resources>  
       <string name="app_name">SpinnerDemo Idroid</string>  
       <string name="item_list">Select Picture</string>  
       <string-array name="spinner">  
            <item>Picture1</item>  
            <item>Picture2</item>  
            <item>Picture3</item>  
       </string-array>  
     </resources>  
       
    
  3. Open your main.xml file and simply change design display as above layout one Spinner top of the screen and below display ImageView for that you need to modify main.xml file under layout folder.
     <?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"  
       >  
         
       <Spinner  
            android:layout_width="fill_parent"  
            android:layout_height="wrap_content"  
            android:entries="@array/spinner"  
            android:prompt="@string/item_list"  
            android:id="@+id/spin1"/>  
              
       <ImageView  
            android:layout_width="fill_parent"  
            android:layout_height="fill_parent"  
            android:id="@+id/imgv1"/>  
         
     </LinearLayout>  
    
  4. Now put three images in res>drawable folder particular size which you want to display and also give proper name for images after that modify your MainActivity.java file given below.
     <?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"  
       >  
         
       <Spinner  
            android:layout_width="fill_parent"  
            android:layout_height="wrap_content"  
            android:entries="@array/spinner"  
            android:prompt="@string/item_list"  
            android:id="@+id/spin1"/>  
              
       <ImageView  
            android:layout_width="fill_parent"  
            android:layout_height="fill_parent"  
            android:id="@+id/imgv1"/>  
         
     </LinearLayout>  
    

Download Source Code :Android_Spinner_Demo.zip