RSS

Search Engine

Sunday, December 12, 2010

Simple Sppiner Example In Android

Hello Friend ,

This are the simple spinner in android.

In Android, Spinner is nothing but a combo box or list box.

It lets you viewing multiple items and allows you to select one item from the list.

Edit Your XML code like this And it is very simple xml code.

main.xml

<?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:id="@+id/spin"
/>
</LinearLayout>


And Now code for java given below.


spinner.java

package com.spinner;

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

public class spinner extends Activity {
/** Called when the activity is first created. */
private String array_spinner[];

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

array_spinner = new String[5];
array_spinner[0] = "Name";
array_spinner[1] = "Address";
array_spinner[2] = "Phone";
array_spinner[3] = "Mobile";
array_spinner[4] = "Home";
Spinner s = (Spinner) findViewById(R.id.spin);
ArrayAdapter adapter = new ArrayAdapter(this,
android.R.layout.simple_spinner_item, array_spinner);
s.setAdapter(adapter);

}
}

And Now The OUTPUT Given Below.


2 comments:

Ravish Pandey said...

great tutorial:)

Anonymous said...

Thanks !!!
this really helped me to get desired output :)

Post a Comment