android - Refreshing the list and the data to the list is coming from asynctask -


i having list should refreshed when user clicks on button.the data on list comming json , m parsing , dispaying in list.now prob when user clicks on button asynctask class whch json parsing shud b called , list should b refreshed

customlist

public class bestcandidatecustomlist extends baseadapter {     context c;     arraylist<hashmap<string, string>> data;     private progressdialog pdialog;     public string cost, comments;     edittext etcost, etcomments;     string success;     button btapply;       public bestcandidatecustomlist(context c, arraylist<hashmap<string, string>> data) {         super ();         this.c = c;         this.data = data;       }      @override     public int getcount() {         return data.size ();     }      @override     public object getitem(int i) {         return null;     }      @override     public long getitemid(int i) {         return 0;     }      @override     public view getview(final int i, view view, viewgroup viewgroup) {          final viewholder holder;         if (view == null) {             holder = new viewholder (); //            view = layoutinflater.from (c).inflate (r.layout.best_candidate_custom_list, viewgroup, false);             view = layoutinflater.from (c).inflate (r.layout.best_candidate_custom_list, viewgroup, false);  //            view.settag (resultp);             holder.name = (textview) view.findviewbyid (r.id.tv_name);             holder.gender = (textview) view.findviewbyid (r.id.tv_gender);             holder.age = (textview) view.findviewbyid (r.id.tv_age);             holder.profession = (textview) view.findviewbyid (r.id.tv_profession);             holder.mobile = (textview) view.findviewbyid (r.id.tv_mobile);             holder.expyrs = (textview) view.findviewbyid (r.id.tv_exp_yrs);             holder.mnths = (textview) view.findviewbyid (r.id.tv_exp_mnths);             holder.apply = (button) view.findviewbyid (r.id.bt_apply);             btapply = (button) view.findviewbyid (r.id.bt_apply);             view.settag (holder);         } else {              holder = (viewholder) view.gettag ();         }          if (data.get (i).get ("status").equals ("null")) {             holder.apply.settext ("apply");         } else {             holder.apply.settext (data.get (i).get ("status"));             if (holder.apply.gettext ().equals ("applied")) {                 holder.apply.setenabled (false);             }           }  //        if (holder.apply.gettext ().equals ("applied")) { //            holder.apply.setfocusable (false); //            holder.apply.setclickable (false); //            holder.apply.setfocusableintouchmode (false); //            holder.apply.setenabled (false); // // //        }          holder.apply.setonclicklistener (new view.onclicklistener () {             @override             public void onclick(view view) {                 final dialog dialog = new dialog (c);                 dialog.setcontentview (r.layout.apply_popup);                 dialog.settitle ("apply");                 etcost = (edittext) dialog.findviewbyid (r.id.et_cost);                 etcomments = (edittext) dialog.findviewbyid (r.id.et_comments);                 holder.ok = (button) dialog.findviewbyid (r.id.bt_ok);                 holder.cancel = (button) dialog.findviewbyid (r.id.bt_cancel);                  holder.ok.setonclicklistener (new view.onclicklistener () {                     @override                     public void onclick(view view) {                         string requestid = data.get (i).get ("requestid");                         string resourceid = data.get (i).get ("resourceid");                         string requestorid = data.get (i).get ("requestorid");                         string entitycode = data.get (i).get ("entitycode");                          apply apply = new apply ();                         apply.execute (requestid, resourceid, requestorid, entitycode);                         holder.apply.setenabled (false);                         dialog.dismiss ();                     }                 });                  holder.cancel.setonclicklistener (new view.onclicklistener () {                     @override                     public void onclick(view view) {                         dialog.dismiss ();                     }                 });                   dialog.show ();             }         });         holder.name.settext (data.get (i).get ("name"));         holder.age.settext (data.get (i).get ("age"));         holder.gender.settext (data.get (i).get ("gender"));         holder.profession.settext (data.get (i).get ("profession"));         holder.mobile.settext (data.get (i).get ("mobile"));         holder.expyrs.settext (data.get (i).get ("exp"));           return view;     }      class viewholder {         textview name;         textview gender;         textview age;         textview profession;         textview mobile;         textview expyrs;         textview mnths;         button apply;         button ok, cancel;       }      public class apply extends asynctask<string, string, string> {         string vendorid = settingpreference.getvendorid (c);         string userid = settingpreference.getuserid (c);         string strcost = etcost.gettext ().tostring ();         string strcomments = etcomments.gettext ().tostring ();          @override          protected string doinbackground(string... strings) {             string response = httprequest.post ("https://beta135.hamarisuraksha.com/web/webservice/hsjobservice.asmx/addjobapplications").send ("ijob_request_id=" + strings[0] + "&ijob_resource_id=" + strings[1] + "&ijob_requestor_id=" + strings[2] + "&ientity_code=" + strings[3] + "&vendor_ientity_code=" + vendorid + "&applied_by_company_ientity_code=" + vendorid + "&create_user_id=" + userid + "&estimated_cost=" + strcost + "&comments=" + strcomments).body ();              response = response.replaceall ("<[^>]*>", "").replaceall ("\n", "");             log.e ("best candidates", "" + response);             return response;         }          @override         protected void onpreexecute() {             super.onpreexecute ();             pdialog = new progressdialog (c);             pdialog.setmessage ("please wait...");             pdialog.setcancelable (false);             pdialog.show ();         }          @override         protected void onpostexecute(string s) {             super.onpostexecute (s);             try {                 jsonobject jsonobject = new jsonobject (s);                 success = jsonobject.getstring ("success");                  if (success.equals ("0")) {                     toast.maketext (c, "apply sucessful", toast.length_long).show ();                   } else {                     toast.maketext (c, "apply unsucessful", toast.length_long).show ();                 }             } catch (jsonexception e) {                 e.printstacktrace ();             }  //            bestcandidate.notifyadapter ();               if (pdialog.isshowing ()) {                 pdialog.dismiss ();             }           }     } } 

mainclass

public class bestcandidate extends activity {     private static listview lvbestcanditate;     static bestcandidatecustomlist customlist;     static context c;     intent i;     textview jobcode, category;     static searchjobs searchjobs;       @override     protected void oncreate(bundle savedinstancestate) {         super.oncreate (savedinstancestate);         setcontentview (r.layout.best_candidate_list);         initialize ();     }      private void initialize() {         = new intent ();         c = bestcandidate.this;          lvbestcanditate = (listview) findviewbyid (r.id.bestcadidate_listview);         jobcode = (textview) findviewbyid (r.id.tv_job_code);         category = (textview) findviewbyid (r.id.tv_category);         customlist = new bestcandidatecustomlist (c, searchjobscustomlist.candidatearray);         lvbestcanditate.setadapter (customlist); //        lvbestcanditate.invalidateviews ();          jobcode.settext (searchjobscustomlist.jobcode);         category.settext (searchjobscustomlist.category);     }       public static void notifyadapter() { //        searchjobscustomlist.bestcandidatedisplay = new searchjobscustomlist.bestcandidatedisplay (); //        a.execute (settingpreference.getbuttonclick (c));         searchjobs.searchjobsasync = new searchjobs.searchjobsasync (c, true);         a.execute ();         customlist = new bestcandidatecustomlist (c, searchjobscustomlist.candidatearray); //        customlist.notifydatasetchanged ();         lvbestcanditate.setadapter (customlist);      }  // } 

while setting adapter (searchjobscustomlist.candidatearray) contains data list,so want update arraylist , refresh list on button click

after asynctask has done task, i.e. in onpostexecute() method can

if (success.equals ("0")) {     toast.maketext (c, "apply sucessful", toast.length_long).show ();     ((baseadapter) yourlistview.getadapter()).notifydatasetchanged(); } else {     toast.maketext (c, "apply unsucessful", toast.length_long).show (); } 

Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -