android - select image from gridview and display it full screen -
i'm using ion library (from link) display image , videos phone in gridview
. need image on clicking in gridview
, display image in activity. would've used integer[position] , getitem()
display image in full screen. how here when i'm using ion library?
public class mainactivity extends activity { private myadapter madapter; private gridview view; // adapter populate , imageview url contained in array adapter public class myadapter extends arrayadapter<string> { public myadapter(context context) { super(context, 0); } @override public view getview(int position, view convertview, viewgroup parent) { // see if need load more 40, otherwise populate adapter if (position > getcount() - 4) loadmore(); if (convertview == null) convertview = getlayoutinflater().inflate(r.layout.image, null); // find image view final imageview iv = (imageview) convertview.findviewbyid(r.id.image); // select image view ion.with(iv) .centercrop() .placeholder(r.drawable.placeholder) .error(r.drawable.error) .load(getitem(position)); return convertview; } } @override public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); ion.getdefault(this).configure().setlogging("ion-sample", log.debug); setcontentview(r.layout.activity_main); int cols = getresources().getdisplaymetrics().widthpixels / getresources().getdisplaymetrics().densitydpi * 2; view = (gridview) findviewbyid(r.id.results); view.setnumcolumns(cols); madapter = new myadapter(this); view.setadapter(madapter); loadmore(); view.setonitemclicklistener(new onitemclicklistener(){ @override public void onitemclick(adapterview<?> parent, view view, int position, long id) { // todo auto-generated method stub toast.maketext(mainactivity.this, madapter.getitem(position), toast.length_short).show(); // here want give intent display image in full screen } }); } cursor mediacursor; public void loadmore() { if (mediacursor == null) { mediacursor = getcontentresolver().query(mediastore.files.getcontenturi("external"), null, null, null, null); } int loaded = 0; while (mediacursor.movetonext() && loaded < 10) { // media type. ion can show images both regular images , video. int mediatype = mediacursor.getint(mediacursor.getcolumnindex(mediastore.files.filecolumns.media_type)); if (mediatype != mediastore.files.filecolumns.media_type_image && mediatype != mediastore.files.filecolumns.media_type_video) { continue; } loaded++; string uri = mediacursor.getstring(mediacursor.getcolumnindex(mediastore.files.filecolumns.data)); file file = new file(uri); // turn file uri if necessary/possible if (file.exists()) madapter.add(file.touri().tostring()); else madapter.add(uri); } } }
view.setonitemclicklistener(new onitemclicklistener(){ @override public void onitemclick(adapterview<?> parent, view view, int position, long id) { // todo auto-generated method stub toast.maketext(mainactivity.this, madapter.getitem(position), toast.length_short).show(); // here want give intent display image in full screen intent = new intent(mainactivity.this, fullscreenviewactivity.class); i.putextra("fullimagepath", madapter.get(position)); mainactivity.this.startactivity(i); }
fullscreenviewactivity
public class fullscreenviewactivity extends activity { imageview fullimage; @override public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); ion.getdefault(this).configure().setlogging("ion-sample", log.debug); setcontentview(r.layout.activity_main); string s = getintent().getstringextra("fullimagepath"); fullimage = (imageview) findviewbyid(r.id.fullimage); ion.with(fullimage) .centercrop() .placeholder(r.drawable.placeholder) .error(r.drawable.error) .load(s); }}
Comments
Post a Comment