java - Data from JSON does not refresh -


i'm developing json parsing app in android, have php script on server fetch data mysql database , encode json, app contact server , populate listview data json using asynctaskloader . it's worked if drop database records, start app again, listview still shows old data. press refresh button call asynctaskloader still old data. don't know why please me.

thank p/s: sorry bad english ^^

sorry, forgot code. here go

tvschedfragment.java

public class tvschedfragment extends listfragment {     private tvschedadapter adpt;     listview lview;     // json node names     private static final string tag_schedule = "sched";     private static string url = "http://192.168.20.205/dom/app/json.php";     string jsonstr;      @override     public view oncreateview(layoutinflater inflater, viewgroup container,             bundle savedinstancestate) {         view rootview = inflater.inflate(r.layout.fragment_tvsched, container,                 false);         lview = (listview) rootview.findviewbyid(android.r.id.list);          adpt = new tvschedadapter(new arraylist<tvschedmodel>(), getactivity());         lview.setadapter(adpt);          (new asynclistviewloader()).execute();         return rootview;     }      @override     public void oncreate(bundle savedinstancestate) {         super.oncreate(savedinstancestate);         sethasoptionsmenu(true);     }      @override     public void oncreateoptionsmenu(menu menu, menuinflater inflater) {         inflater.inflate(r.menu.menu_tvsched, menu);         super.oncreateoptionsmenu(menu, inflater);     }      @override     public boolean onoptionsitemselected(menuitem item) {          switch (item.getitemid()) {         case r.id.menu_tvsched_refresh:             (new asynclistviewloader()).execute();             return true;         }         return super.onoptionsitemselected(item);     }      @override     public void onactivitycreated(bundle savedinstancestate) {         super.onactivitycreated(savedinstancestate);      }      private class asynclistviewloader extends             asynctask<string, void, list<tvschedmodel>> {         private final progressdialog dialog = new progressdialog(getactivity());          @override         protected void onpostexecute(list<tvschedmodel> result) {             super.onpostexecute(result);             dialog.dismiss();             adpt.setitemlist(result);             adpt.notifydatasetchanged();         }          @override         protected void onpreexecute() {             super.onpreexecute();             dialog.setmessage("downloading schedule...");             dialog.show();         }          @override         protected list<tvschedmodel> doinbackground(string... params) {             list<tvschedmodel> result = new arraylist<tvschedmodel>();             servicehandler sh = new servicehandler();              // making request url , getting response             jsonstr = sh.makeservicecall(url, servicehandler.get);             log.d("response: ", "> " + jsonstr);             try {                 jsonobject jsonobj = new jsonobject(jsonstr);                 // getting json array node                 jsonarray contacts = jsonobj.getjsonarray(tag_schedule);                 (int = 0; < contacts.length(); i++) {                     result.add(convertsched(contacts.getjsonobject(i)));                 }                  return result;             } catch (throwable t) {                 t.printstacktrace();             }             return null;         }          private tvschedmodel convertsched(jsonobject obj)                 throws jsonexception {             string name = obj.getstring("program");             string desc = obj.getstring("description");             string time = obj.getstring("datetimestring");             string chan = obj.getstring("channel");             return new tvschedmodel(time, name, desc, chan);         }     }      @override     public void ondestroy() {         super.ondestroy();         adpt.clear();     } } 

servicehandler.java

public class servicehandler {      static string response = null;     public final static int = 1;     public final static int post = 2;      public servicehandler() {      }      /*      * making service call      * @url - url make request      * @method - http request method      * */     public string makeservicecall(string url, int method) {         return this.makeservicecall(url, method, null);     }      /*      * making service call      * @url - url make request      * @method - http request method      * @params - http request params      * */     public string makeservicecall(string url, int method,             list<namevaluepair> params) {         try {             // http client             defaulthttpclient httpclient = new defaulthttpclient();             httpentity httpentity = null;             httpresponse httpresponse = null;              // checking http request method type             if (method == post) {                 httppost httppost = new httppost(url);                 // adding post params                 if (params != null) {                     httppost.setentity(new urlencodedformentity(params));                 }                  httpresponse = httpclient.execute(httppost);              } else if (method == get) {                 // appending params url                 if (params != null) {                     string paramstring = urlencodedutils                             .format(params, "utf-8");                     url += "?" + paramstring;                 }                 httpget httpget = new httpget(url);                  httpresponse = httpclient.execute(httpget);              }             httpentity = httpresponse.getentity();             response = entityutils.tostring(httpentity);          } catch (unsupportedencodingexception e) {             e.printstacktrace();         } catch (clientprotocolexception e) {             e.printstacktrace();         } catch (ioexception e) {             e.printstacktrace();         }          return response;      } } 

if using arrayadapter show list view clear array list on finish() or whenever refresh list.clear previous list store updated data , call adapter.notifydatachanged();.


Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

javascript - jQuery show full size image on click -