Android Simple Spinner Example - ANDROID - Helper

Tuesday, March 15, 2011

Android Simple Spinner Example


SIMPLE SPINNER

SOURCE CODE [main.xml] is

<?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:id="@+id/spin"
android:layout_width="150px"
android:layout_height="wrap_content"
android:layout_gravity="center">
</Spinner>
</LinearLayout>

SOURCE CODE [SpinnerExample.java] is

package com.SpinnerExample;

import android.app.Activity;
import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.Spinner;

public class SpinnerExample extends Activity
{
Spinner sp;
                ArrayAdapter<String> adapter;
                String numbers[] = { "ONE", "TWO", "THREE", "FOUR", "FIVE", "SIX", "SEVEN",
                                                "EIGHT", "NINE", "TEN" };

public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
                                setContentView(R.layout.main);

                                sp = (Spinner) findViewById(R.id.spin);
                               
                                adapter = new ArrayAdapter<String>(this,
                                                                android.R.layout.simple_spinner_item, numbers);
                                sp.setAdapter(adapter);
                }
}

The OUTPUT will be

https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjCMhrjVOooptzGgRiQGk99pGiofZOjxs844NoXOAlPS-R_Fbo5iv9AmWP1F62bVELCUvoNQ8pXdUUtWXnxReW-lL1rSAu5mEDi3FCMSO05erZfWWiHaMoBT9tAFtIthneV2tm57Rg77WA/ https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi_jX3GPFuvjrJA2sFxb36LBJlFrhzavNYsQ11DniMjjrDGpp_xyLJJ-0YfbYXOkEEPV6ndhv0zldtd-ys_exG0IooTZs8MuTRrSKXZij5MIB0v93ys8VNSSI3Y_S0vWsOu-OtPzMNLIkw/

3 comments:

  1. hi jack,


    your all codes are really good and useful.Thank you for this blog.But i am getting the output window and the box with this document. but i don't get that one in the window itself. can you tell me is any changes need to be made in the string.xml and Androidmanifest.xml ? so that i can get the perfect output. can you help me jack. or if you can send the code. Kindly send to me the with string.xml Androidmanifest.xml all the codes to my mail id
    deepichilldeepi@gmail.com.

    ReplyDelete
  2. hi jack,


    your all codes are really good and useful.Thank you for this blog.But i am getting the output window and the box with this document. but i don't get that one in the window itself. can you tell me is any changes need to be made in the string.xml and Androidmanifest.xml ? so that i can get the perfect output. can you help me jack. or if you can send the code. Kindly send to me the with string.xml Androidmanifest.xml all the codes to my mail id
    deepichilldeepi@gmail.com.

    ReplyDelete
  3. Hai jack your codes are very use full thanks lots........

    ReplyDelete