Reputation: 575
How to get spinner selected value in another screen?
Suppose I have 3 options in Login Screen
wifi
Gprs
SMS
I select option 3 in Login Screen for spinner value and
when I go another activity how do I set the spinner value like this manner
if selected position is 3
true
else
false
Or any other way I make check to know which value is selected on Last screen?
Upvotes: 0
Views: 2622
Reputation: 33
String selectedItem = YourActivtyName.spinnername.getSelectedItem().toString();
using static you can access data members in another classes or activity.
in your activity you have to declare the Spinner name as public static.
Upvotes: 0
Reputation: 51
You can take the index of selected item and pass it to next activity.In the second activity set this item as selected
Upvotes: 1
Reputation: 6141
Use intExtra in intent to pass value (1,2,3) to the second activity, where you can use getIntent().getExtra() to read that int. Based on its value you know what was selected on spinner.
Example: In LoginActivity:
Intent intent=new Intent(LoginActivity.this,SecondActivity.class);
intent.putExtra("CODE",1);
startActivity(intent);
finish();
In SecondActivity:
Intent intent = getIntent();
int code=intent.getIntExtra("CODE",0);
Then based on code value you know what was selected.
Upvotes: 2
Reputation: 2534
You can use putExtra()
and getExtra()
in activity.
Write in your activity where you have to send data.
Intent intent = new Intent(YourCurrentActivity.this,YourNextActivity.class);
intent.putExtra("Value", spinnerValue);
startActivity(intent);
While receiving use this
String getSpinnerValue = getIntent().getExtras().getString("Value");
Upvotes: 1
Reputation: 2494
Passing value from one activity to another activity by means of putExtras() and getExtras()
Intent in=new Intent(currentActivity.this,nextActivity.class);
in.putExtras("passingvalue_attribute","passvalue");
startActivity(in);
finish();
For getting value.
String value=getIntent().getExtras().getString("passingvalue_attribute"); // its for string likewise you can send and get boolean and integer also..
I think it may helpful to you..
Upvotes: 0