CVD
CVD

Reputation: 27

how to display the spinner selected values to text view in another activity

I have two activities namely activity1 and activity2.

In my first activity I have a spinner and in my second activity I have a text view(txt1).

Here, all I want is that when a spinner value is selected, the selected value of that spinner should be displayed in the text view in second activity.


I can display the selected value of the spinner in text view in same activity but I don't know how to display in activity2 with text view...

Kindly pls help...

Upvotes: 0

Views: 3084

Answers (2)

ManiTeja
ManiTeja

Reputation: 847

Try this it will work:

activity1.class:

Intent i = new Intent(activity1.this,activity2.class);

Bundle b = new Bundle();
b.putString("name", sp.getSelectedItem().toString());

i.putExtras(b);
startActivity(i);

activity2.class:

Bundle b = this.getIntent().getExtras();

String name = b.getString("name");

((TextView)findViewById(R.id.textView1)).setText(name);

Upvotes: 2

dymmeh
dymmeh

Reputation: 22306

You'll need to pass the value you want to display through your intent to launch activity2. Look at the answer posted here Android: How to pass the data to sub-activities? on how to do it. It shows you the concept of how to pass a value from one activity to another.

Upvotes: 0

Related Questions