Home > Android > Android Spinner Example

Android Spinner Example

android spinner adapter source code download

Android For Fresher 

Android Spinner Example

Android Spinner Example

Java Code(SpinnerAct)

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.Spinner;
import android.widget.Toast;

public class SpinnerAct extends Activity {
Spinner sp1;
@Override protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_spinner);

sp1 = (Spinner)findViewById(R.id.sp1);

String items[] = {“C”, “C++”, “Java”, “.net”, “Android”};

ArrayAdapter aa = new ArrayAdapter(this, android.R.layout.simple_dropdown_item_1line, items);

sp1.setAdapter(aa);
}

public void displayData(View v)

{
String item = (String) sp1.getSelectedItem();

Toast.makeText(this, item, Toast.LENGTH_SHORT).show();
}
}


Layout XML code(activity_spinner)

<?xml version=”1.0″ encoding=”utf-8″?>

<LinearLayout xmlns:android=”http://schemas.android.com/apk/res/android”
xmlns:tools=”http://schemas.android.com/tools”
android:layout_width=”match_parent”
android:orientation=”vertical”
android:layout_height=”match_parent”
android:paddingBottom=”@dimen/activity_vertical_margin”
android:paddingLeft=”@dimen/activity_horizontal_margin”
android:paddingRight=”@dimen/activity_horizontal_margin”
android:paddingTop=”@dimen/activity_vertical_margin”
tools:context=”com.andro.tech.androidproject.SpinnerAct”>

<TextView
android:layout_width=”wrap_content”
android:layout_height=”wrap_content”
android:textSize=”@dimen/textsize”
android:layout_gravity=”center”
android:textStyle=”bold”
android:text=”SPINNER”
android:layout_marginBottom=”20dp” />

<Spinner
android:layout_width=”wrap_content”
android:layout_height=”wrap_content”
android:id=”@+id/sp1″
android:layout_gravity=”center”
android:layout_marginBottom=”80dp”>
</Spinner>

<Button
android:layout_width=”match_parent”
android:layout_height=”wrap_content”
android:onClick=”displayData”
android:text=”SUBMIT”
android:layout_marginBottom=”150dp”/>

<Button
android:layout_width=”match_parent”
android:layout_height=”wrap_content”
android:text=”@string/sourcecode”
android:background=”@color/bgcolor”
android:textStyle=”bold”
android:textColor=”@color/text”
android:onClick=”view1″/>

</LinearLayout>

Android Spinner Example Output :

android spinner adapter source code download

Download Spinner Source Code

For More Android Programs –Click Here

 

Follow Us – Never Miss Update

Fb/PageTwitterGoogle+InstagramPinterest 

 

Related Search

Android Spinner snippet source code download, android spinner snippet for beginners, spinner code download, spinner code download snippet, android source code spinner list, android list spinner source code download, android drop down snippet source code download, spinner adapter source code download, android spinner adapter source code download

Is This Content Useful For You?