android - Trying to refresh Gridview in Universal Image Loader after delete -
i displaying images in gridview universal image loader. images database. added context menu delete pictures needed out of database. works great there. after deleting picture need refresh view it's still displaying deleted picture. (i used default setup uil , did not enable caching) tried call destroy , init imageloader , called async task query images again gives me error saying file not found (the deleted one). here (lengthy) code. can see missing?
gridview gridview; adaptercontextmenuinfo info; imageloaderconfiguration config; imageview imageview; arraylist<string> pictures = new arraylist<string>(); @override public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.ac_image_grid); config = new imageloaderconfiguration.builder(this).build(); imgloader = imageloader.getinstance(); imgloader.init(config); class getalbum extends asynctask<string, string, string> { //pre execute here @override protected string doinbackground(string... args) { int success; try { list<namevaluepair> params = new arraylist<namevaluepair>(); params.add(new basicnamevaluepair("username", restoredemail)); params.add(new basicnamevaluepair("album_name", album_name)); json = jsonparser.makehttprequest(login_url, "post", params); success = json.getint(tag_success); if (success == 1) { mpictures = json.getjsonarray(tag_posts); // looping through posts according json object // returned (int = 0; < mpictures.length(); i++) { jsonobject c = mpictures.getjsonobject(i); string dir = c.getstring("dir"); string album = c.getstring("album"); string pic = c.getstring("photo"); string picture = thecompletedpicture; pictures.add(picture); } return json.getstring(tag_message); } else { log.d("login failure!", json.getstring(tag_message)); return json.getstring(tag_message); } } catch (jsonexception e) { e.printstacktrace(); } return null; } protected void onpostexecute(string file_url) { pdialog.dismiss(); setpictures(); } } private void setpictures() { // todo auto-generated method stub gridview = (gridview) findviewbyid(r.id.gridview); gridview.setadapter(new imageadapter(this, pictures)); registerforcontextmenu(gridview); gridview.setonitemclicklistener(new onitemclicklistener() { @override public void onitemclick(adapterview<?> parent, view view, int position, long id) { startimagepageractivity(position); } }); } // , context menu makes // async thread delete picture , // remove database. on // post execute put call load pictures again // problem is. need display // remaining pictures. maybe trying remove deleted // picture array , reloading it? need // code. protected void onpostexecute(string file_url) { // dismiss dialog once product deleted pdialog.dismiss(); imgloader.destroy(); imgloader.init(config); new getalbum().execute(); }
try using empty image cache:
collection<string> c = imageloader.getinstance().getmemorycache().keys(); for(string key : c) { try { memorycacheutil.removefromcache(key, imageloader.getinstance().getmemorycache()); } catch(exception ex) {ex.printstacktrace();} }
Comments
Post a Comment