Reputation: 575
How do I get spinner selected position in intent and pass it as parameter to another Activity?
spinner sp;
if (position==1) {
do this
} if (position==2) {
do this
}
Intent i = new Intent(this.getApplicationContext(), AgAppMenu.class);
Bundle bundle = new Bundle();
bundle.putString("mno", mobile.getText().toString());
bundle.putString("pinno", pin.getText().toString());
bundle.putLong("CODE",sp.getSelectedItemPosition());
Upvotes: 0
Views: 1634
Reputation: 3117
String item;
sp.setOnItemSelectedListener(new OnItemSelectedListener() {
public void onItemSelected(AdapterView<?> arg0, View arg1,int arg2, long arg3) {
item = (String) arg0.getItemAtPosition(arg2);
}
public void onNothingSelected(AdapterView<?> arg0) {
// TODO Auto-generated method stub
}
});
Intent i = new Intent(this.getApplicationContext(), AgAppMenu.class);
Bundle bundle = new Bundle(); bundle.putString("CODE",item);
Upvotes: 0
Reputation: 566
Perhaps this is what you want to do?
sp.setOnItemSelectedListener(new OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> av, View v,
int pos, long id) {
//do something with the pos var
}
@Override
public void onNothingSelected(AdapterView<?> arg0) {}
});
Upvotes: 1
Reputation: 1698
define a class variable (here String selectedMonth) and assign it value in the following method and then use this variable in intent
public void onItemSelected(AdapterView month, View arg1,int arg2, long arg3) {
selectedMonth= month.getItemAtPosition(arg2).toString();
}
Upvotes: 0
Reputation: 22156
If I understood correctly. Now all you are missing is
intent.putExtras(bundle);
startActivity(intent);
EDIT:
To get the value, use
(YourType) sp.getSelectedItem();
where YourType
is the type of the value you wish to get. If it's Long
, cast it to Long
.
Upvotes: 0