android - Gridview adapter from custom folder in sdcard -


i m currenly using nhaarman gridview , want bitmap custom folder. gridview in fragment , pull image "test" folder , show it. emulator able run code, not in real phone. please help. thanks.

@override public view oncreateview(layoutinflater inflater, viewgroup container, bundle savedinstancestate) {     view view = inflater.inflate(r.layout.activity_home_fragment_month, container, false);      gridview gridview = (gridview) view.findviewbyid(r.id.activity_gridview_gv);       //---------------------------------------------------------------------------     file = new file(environment.getexternalstoragedirectory()             + file.separator + "test");     // check sd card     if (!environment.getexternalstoragestate().equals(             environment.media_mounted)) {         toast.maketext(getactivity(), "error! no sdcard found!", toast.length_long)                 .show();     } else {          if(file.exists()==false){             // locate image folder in sd card             file = new file(environment.getexternalstoragedirectory()                     + file.separator + "test");             // create new folder if no folder named test exist             file.mkdirs();         }     }      if (file.isdirectory()) {         listfile = file.listfiles();         // create string array filepathstrings         filepathstrings = new string[listfile.length];         // create string array filenamestrings         filenamestrings = new string[listfile.length];          (int = 0; < listfile.length; i++) {             // path of image file             filepathstrings[i] = listfile[i].getabsolutepath();             // name image file             filenamestrings[i] = listfile[i].getname();         }     }      swingbottominanimationadapter swingbottominanimationadapter = new swingbottominanimationadapter(new myadapter(getactivity().getapplicationcontext(), getitems()));     swingbottominanimationadapter.setabslistview(gridview);     swingbottominanimationadapter.setinitialdelaymillis(300);      adapter = new gridviewadapter(getactivity(), filepathstrings, filenamestrings);     //gridview.setadapter(swingbottominanimationadapter);     gridview.setadapter(adapter);      return view; } 

public class gridviewadapter extends baseadapter {

    // declare variables     private context activity;     private string[] filepath;    // file path , environment.getexternalstoragedirectory()+ file.separator +        "test"     private string[] filename;      private layoutinflater inflater = null;      public gridviewadapter(context a, string[] fpath, string[] fname) {         activity = a;         filepath = fpath;         filename = fname;         inflater = (layoutinflater) activity                 .getsystemservice(context.layout_inflater_service);      }      public int getcount() {         return filepath.length;      }      public object getitem(int position) {         return position;     }      public long getitemid(int position) {         return position;     }      public view getview(int position, view convertview, viewgroup parent) {          imageview imageview = (imageview) convertview;          if (imageview == null) {             imageview = new imageview(activity);             imageview.setscaletype(imageview.scaletype.center_crop);         }          // decode filepath bitmapfactory followed position         bitmap bmp = bitmapfactory.decodefile(filepath[position]);          // set decoded bitmap imageview         imageview.setimagebitmap(bmp);          return imageview;     } } 

are deploying apk on device or using testing ? because adding permissions might issue here if deploying apk on real device.


Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -