java - pass a selected value in a spinner array to another class Android -
im building app has self destructing images , trying pass value selected spinner class
final string titles[] = {"1 second","2 seconds", "3 seconds","4 seconds","5 seconds","6 seconds","7 seconds", "8 seconds, "9 seconds", 10 seconds}; mseconds = (spinner) view.findviewbyid(r.id.secondsspinner); arrayadapter<string> arrayadapter = new arrayadapter<string>(getactivity(), android.r.layout.simple_spinner_item, titles); arrayadapter.setdropdownviewresource(android.r.layout.simple_spinner_dropdown_item); mseconds.setadapter(arrayadapter); mseconds.setonitemselectedlistener(new adapterview.onitemselectedlistener() { @override public void onitemselected(adapterview<?> parentview, view selecteditemview, int position, long id) { int secondstouse = position + 1; } @override public void onnothingselected(adapterview<?> parentview) { // nothing } });
my intent method:
intent recipientsintent = new intent(getactivity(), recipientsactivity.class); recipientsintent.putextra("key1", titles); startactivity(recipientsintent);
how can pass value selected class? method passes whole array not item selected.
spinner.getselecteditem();
will selected item .
intent recipientsintent = new intent(getactivity(), recipientsactivity.class); recipientsintent.putextra("spinneritem", spinner.getselecteditem()); startactivity(recipientsintent);
if need logic behind lmk.. spinner.getselecteditem()
return object. you'll need cast whatever you're expecting. string example... spinner.getselecteditem().tostring()
to pass int in intent:
intent recipientsintent = new intent(getactivity(), recipientsactivity.class); recipientsintent.putextra("your_int_key", secondstouse); startactivity(recipientsintent);
the reason int isn't working in intent because it's local variable onitemselected() function. make member variable or put outside onitemselected
Comments
Post a Comment