android - How to populate GridView if Internet not available but images already cached to SD Card -


hello writing application in parsing json images , caching sd card.

what want ?

i want load images gridview json (by caching images sd card), , wanna populate gridview (no matter internet available or not) once images downloaded sd card.

what getting ?

i able cache images sd card, populate gridview, not able show images gridview (if internet not available) images cached sd card

    @override     protected void oncreate(bundle savedinstancestate) {         super.oncreate(savedinstancestate);         setcontentview(r.layout.activity_grid_view);          gridview = (gridview) findviewbyid(r.id.grid_view);          utils = new util(this);          // initilizing grid view         initilizegridlayout();         // gridview adapter         new getimages().execute();     }      private void initilizegridlayout() {         resources r = getresources();         float padding = typedvalue.applydimension(typedvalue.complex_unit_dip,                 appconstant.grid_padding, r.getdisplaymetrics());          columnwidth = (int) ((utils.getscreenwidth() - ((appconstant.num_of_columns + 1) * padding)) / appconstant.num_of_columns);          gridview.setnumcolumns(appconstant.num_of_columns);         gridview.setcolumnwidth(columnwidth);         gridview.setstretchmode(gridview.no_stretch);         gridview.setpadding((int) padding, (int) padding, (int) padding,                 (int) padding);         gridview.sethorizontalspacing((int) padding);         gridview.setverticalspacing((int) padding);     }     class getimages extends asynctask<string, void, string> {          @override         protected string doinbackground(string... params) {             // todo auto-generated method stub             jsonobject json = jsonfunctions.getjsonfromurl(location);              try {                 jsonarray jarray;                 jarray = json.getjsonarray(tag_items);                 (int = 0; < jarray.length(); i++) {                     jsonobject gridimages = jarray.getjsonobject(i);                     imagepaths.add(gridimages.getstring("saved_location"));                 }              } catch (jsonexception e) {                 // todo auto-generated catch block                 e.printstacktrace();             }              return null;         }          @override         protected void onpostexecute(string result) {             // todo auto-generated method stub             super.onpostexecute(result);             adapter = new gridviewimageadapter(gridviewactivity.this, imagepaths,                     columnwidth);              // setting grid view adapter             gridview.setadapter(adapter);         }     } } 

here complete solution of viewing images server via json online offline too..

  1. dbadapter

  2. gridviewactivity

  3. fullscreenviewactivity

hoping solve problem.

thanks


Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

ios - Change Storyboard View using Seague -