java - Passing array from one android activity to another and using it in a spinner -
in source code, have 2 activities. in activity a.java have array
private string[] typename = new string[100];
and starting new activity
public void loadcuecardset(view view){ intent loadcuecardpage = new intent(this, loadcuecardset.class); loadcuecardpage.putextra("types", typename); startactivity(loadcuecardpage); }
in second activity, have
protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_load_cue_card_set); // array of choices // selection of spinner spinner spinner = (spinner) findviewbyid(r.id.spinner); // application of array spinner bundle extras = getintent().getextras(); string colors[] = extras.getstringarray("types"); // doesn't work arrayadapter<string> spinnerarrayadapter = new arrayadapter<string>(this, android.r.layout.simple_spinner_item, colors); spinnerarrayadapter.setdropdownviewresource(android.r.layout.simple_spinner_dropdown_item); // drop down view spinner.setadapter(spinnerarrayadapter);
i know problem spinner , has array passing it, problem should work because tried actual array created in second activity. code below works if don't use array passed activity.
protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_load_cue_card_set); // array of choices // selection of spinner spinner spinner = (spinner) findviewbyid(r.id.spinner); // application of array spinner string colors[] = {"red"}; //works arrayadapter<string> spinnerarrayadapter = new arrayadapter<string>(this, android.r.layout.simple_spinner_item, colors); spinnerarrayadapter.setdropdownviewresource(android.r.layout.simple_spinner_dropdown_item); // drop down view spinner.setadapter(spinnerarrayadapter);
Comments
Post a Comment