How to reload a spinner in Android? -
can tell me code reload spinner?
i have created small app can add items , delete unwanted items. items added showed in spinner. once select item spinner , delete clicking delete button, item getting deleted database & toast displayed "item deleted". still showing in spinner until logout , logs in once again. here, think need reload spinner once again on delete button click. can me out that?
public class deletechildactivity extends activity { textview name; button delete; spinner spinner2; private string url = "/parentprofileservlet"; private string url1 = "/childprofileservlet"; private string url2 = "/deletechildservlet"; arraylist<namevaluepair> postparameter; public static int selectchildid; public static string imei; parentdetailsmod parentmodel; private arraylist<childdetails> childarray = null; public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.delete_child); delete = (button) findviewbyid(r.id.b_delchild); spinner2 = (spinner) findviewbyid(r.id.childspinner); childarray = new selectparser().parseselectxml(response); arraylist<string> stringarray = new arraylist<string>(); (childdetails childmodel : childarray) { string str; str = childmodel.getname(); stringarray.add(str); } // spinner = (spinner) findviewbyid(r.id.spinner11); arrayadapter<string> adapter = new arrayadapter<string>( getapplicationcontext(), android.r.layout.simple_list_item_1, stringarray); adapter.setdropdownviewresource(android.r.layout.simple_spinner_dropdown_item); spinner2.setadapter(adapter); spinner2.setprompt(getstring(r.string.selectlabel)); spinner2.setonitemselectedlistener(new adapterview.onitemselectedlistener() { @override public void onitemselected(adapterview<?> arg0, view arg1, int position, long arg3) { imei = childarray.get(position).getimei_num(); selectchildid = childarray.get(position).getchild_id(); } @override public void onnothingselected(adapterview<?> arg0) { // todo auto-generated method stub } }); delete.setonclicklistener(new view.onclicklistener() { @override public void onclick(view v) { // spinner.performclick(); // string id = spinner2.getselecteditem().tostring(); // selectchildid = id.substring(0, id.indexof("--")); postparameter = new arraylist<namevaluepair>(); string parent_id = loginpageactivity.id; postparameter .add(new basicnamevaluepair("parent_id", parent_id)); postparameter.add(new basicnamevaluepair("child_id", selectchildid + "")); string response = null; try { response = customhttpclient.executehttppost(url2, postparameter); system.out.println("response:" + response); if (response.trim().compareto("success") == 0) { toast.maketext(getapplicationcontext(), "child deleted", toast.length_long).show(); } else { toast.maketext(getapplicationcontext(), "failed delete", toast.length_long).show(); } } catch (exception e) { // todo auto-generated catch block e.printstacktrace(); } } });
you can use notifydatasetchanged(); method reload adapter or display changed data.
Comments
Post a Comment