c# - Xamarin Image Grid from Folder -
i trying display image grid text. using images folder. have tries various approaches , tutorials no success. have both read , write permissions internal , external storage. whenever debug application blank screen. have tried setting breakpoint on adapters getview() method never gets hit.
here mainactivity oncreate() method:
protected override void oncreate(bundle bundle) { if (!_dir.exists()) { _dir.mkdir(); } base.oncreate(bundle); setcontentview(r.layout.main); string[] filepath = null; string[] filename = null; if (_dir.isdirectory) { droidio.file[] imagelist = _dir.listfiles(); filepath = new string[imagelist.length]; filename = new string[imagelist.length]; (int = 0; < imagelist.length; i++) { filepath[i] = imagelist[i].absolutepath; filename[i] = imagelist[i].name; } } var gvimagelist = findviewbyid<gridview>(r.id.gvimagelist); gvimagelist.setadapter(new imagesfromfolderadapter(this, filepath, filename)); gvimagelist.itemclick += delegate { gvimagelist_itemclick(); }; }
and image adapter class:
public class imagesfromfolderadapter : baseadapter { private activity context; private string[] filepath; private string[] filename; public imagesfromfolderadapter(activity c, string[] fp, string[] fn) { this.context = c; this.filename = fn; this.filepath = fp; } public override int count { get; } public int getcount() { return filepath.length; } public override java.lang.object getitem(int position) { return position; } public override long getitemid(int position) { return position; } public override view getview(int position, view convertview, viewgroup parent) { view view = convertview; if (view == null) view = context.layoutinflater.inflate(r.layout.gallery_item_layout, null); view.findviewbyid<imageview>(r.id.gitemimage).setimagebitmap(bitmapfactory.decodefile(filepath[position])); view.findviewbyid<textview>(r.id.gitemtext).text = filename[position]; return view; } }
any ideas going wrong? using lg g3 debug device if helps. thankyou in advance.
you returned 0 count grid adapter.
change
public override int count { get; }
to
public override int count { { return filepath.length; } }
Comments
Post a Comment