Update content of spinner after selecting item in Android

19 May

Are your spinners in different activities?

If they are, so you can just pass the selected value of the first spinner via Intent (See the putExtra section) and retrieve the value from the next activity so that you can set accordingly the next spinners.


Here is an example that changes the selected item in the 2nd and 3rd spinner. Update the listener (onItemSelected method) with your logic

private Spinner s;
private Spinner s2;
private Spinner s3;

protected void onCreate(Bundle savedInstanceState) {

String[] myList = new String[] { “Hello”, “World”, “Foo”, “Bar” };
String[] myList2 = new String[] { “Hello2″, “World2″, “Foo2″, “Bar2″ };
String[] myList3 = new String[] { “Hello3″, “World3″, “Foo3″, “Bar3″ };

s = (Spinner) findViewById(;
s2 = (Spinner) findViewById(;
s3 = (Spinner) findViewById(;

s.setAdapter(new ArrayAdapter(this,android.R.layout.simple_spinner_item, myList));
s2.setAdapter(new ArrayAdapter(this,android.R.layout.simple_spinner_item, myList2));
s3.setAdapter(new ArrayAdapter(this,android.R.layout.simple_spinner_item, myList3));

s.setOnItemSelectedListener(new OnItemSelectedListener(){

public void onItemSelected(AdapterView parent, View v,
int pos, long id) {

public void onNothingSelected(AdapterView arg0) {



<?xml version=”1.0″ encoding=”utf-8″?>
<LinearLayout android:layout_width=”fill_parent” xmlns:android=””
<Spinner android:id=”@+id/spinner1″ android:layout_height=”wrap_content” android:layout_width=”fill_parent” />
<Spinner android:id=”@+id/spinner2″ android:layout_height=”wrap_content” android:layout_width=”fill_parent” />
<Spinner android:id=”@+id/spinner3″ android:layout_height=”wrap_content” android:layout_width=”fill_parent” />

Leave a comment

Posted by on May 19, 2012 in Android Source Code


Tags: , ,

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: