java - Android Images Folder in a ImageView -
sorry in advance english.
i want import images folder of smartphone. want used these images gallery. problem when put images in array, after can't put each images of array in imageview.
it's code using gallery
public class seegallery extends activity { file[] listfile ; public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_see_gallery); file folder = new file(environment.getexternalstoragedirectory() + "/projectkozaimages"); listfile = folder.listfiles(); // note gallery view deprecated in android 4.1--- gallery gallery = (gallery) findviewbyid(r.id.gallery1); gallery.setadapter(new imageadapter(this)); gallery.setonitemclicklistener(new onitemclicklistener() { public void onitemclick(adapterview<?> parent, view v, int position,long id) { // display images selected imageview imageview = (imageview) findviewbyid(r.id.image1); imageview.setimageresource(listfile[position]); } }); } public class imageadapter extends baseadapter { private context context; private int itembackground; public imageadapter(context c) { context = c; // sets grey background; wraps around images typedarray =obtainstyledattributes(r.styleable.mygallery); itembackground = a.getresourceid(r.styleable.mygallery_android_galleryitembackground, 0); a.recycle(); } // returns number of images public int getcount() { return listfile.length; } // returns id of item public object getitem(int position) { return position; } // returns id of item public long getitemid(int position) { return position; } // returns imageview view public view getview(int position, view convertview, viewgroup parent) { imageview imageview = new imageview(context); imageview.setimageresource(listfile[position]); imageview.setlayoutparams(new gallery.layoutparams(100, 100)); imageview.setbackgroundresource(itembackground); return imageview; } }
thank in advance help
i think need convert filepath stored in filearray bitmap first...
bitmap bitmap = bitmapfactory.decodefile(listfile[position].getabsolutepath()); imageview.setimagebitmap(bitmap);
Comments
Post a Comment