Android: Spinners loose their values when I add dynamically new ListView entries on click of spinner item? -
i developing android apps. in apps having 2 activities, first activity displaying list , in second activity having spinner , listview in same activity , when user click on item spinner listview displayed. when user navigate first activity second activity spinner populated listview. problem after listview displayed spinner item blank. don't know doing wrong. please have solution.
here posting few code of second activity
public class projectdetailactivity extends sherlocklistactivity { private list<string> list = new arraylist<string>(); private arraylist<hashmap<string, string>> list2 = new arraylist<hashmap<string,string>>(); protected void oncreate(bundle savedinstancestate) { // todo auto-generated method stub super.oncreate(savedinstancestate); setcontentview(r.layout.activity_project_detail); //get spinner item server when user comes first activity. new loadphasedata().execute(); //listener phase spinner projspinnerphase.setonitemselectedlistener((onitemselectedlistener) new onitemselectedlistener() { @override public void onitemselected(adapterview<?> arg0, view arg1, int arg2, long arg3) { //get listview when user click item spinner new loadphasedata().execute(); } @override public void onnothingselected(adapterview<?> arg0) { } }); //this adapter listview when click item spinner listadapter phaseadapter = new simpleadapter(getapplicationcontext(), list2, r.layout.phase_avail_list_item, new string[] {phase_name}, new int[] {r.id.phasename}); setlistadapter(phaseadapter); } private class loadphasedata extends asynctask<string, void, void> { @override protected void doinbackground(string... params) { //here calling web service spinner , listview } @override protected void onpostexecute(void result) { //following adapter spinner item arrayadapter<string> dataadapter = new arrayadapter<string>( getapplicationcontext(),android.r.layout.simple_spinner_item,list); dataadapter.setdropdownviewresource( android.r.layout.simple_spinner_dropdown_item); projspinnerphase.setadapter(dataadapter); } } }
thanks in advance
this because assigning new adapter spinner
new values while adding new rows spinner
. spinner losses previous row along previous data , adapter new data rows. need append these value existing data-holder (may array or arraylist) , call adapter.notifydatasetchanged();
you need move arraylist class-level, (i.e make class field) while have downloaded data. append new data list
, call adapter.notifydatasetchanged();
Comments
Post a Comment