c# - Dialogbox bug (Xamarin Android) -


i have following code passes intent whether select_image or request_camera. in case, after adding image gallery, item added on listview.

protected override void onactivityresult(int requestcode, result resultcode, intent data)     {         // ................ //          if (resultcode == result.ok)         {             if (requestcode == request_camera)             {                 // ...................//             }             else if ((requestcode == select_file) && (data != null))             {                 android.net.uri uri = data.data;                 string imguri = convert.tostring(uri.lastpathsegment);                 string senduri = convert.tostring(uri);                  myfilelistadapter.add(senduri);                 myfilelistadapter.notifydatasetchanged();                 setlistviewheightbasedonchildren(listviewfiles);                  if (myfilelistadapter.count == 5)                 {                     btnadd.enabled = false;                 }                  listviewfiles.itemclick += clickhandler;             }         }     } 

upon clicking item listview, dialogbox appear showing image. in dialogbox, there 2 options: cancel , delete (image).

public void clickhandler(object sender, itemclickeventargs e)     {         string path = listviewfiles.getitematposition(e.position).tostring();         android.net.uri uri2 = android.net.uri.parse(path);          string[] proj = { mediastore.images.imagecolumns.data };         var cursor = contentresolver.query(uri2, proj, null, null, null);         var colindex = cursor.getcolumnindex(mediastore.images.imagecolumns.data);         cursor.movetofirst();         bitmapfactory.options options = new bitmapfactory.options { injustdecodebounds = true };         bitmapfactory.decodefile(cursor.getstring(colindex), options);         int height = 250;         int width = resources.displaymetrics.widthpixels;         int outheight = options.outheight;         int outwidth = options.outwidth;         int insamplesize = 1;          if (outheight > height || outwidth > width)         {             insamplesize = outwidth > outheight                                ? outheight / height                                : outwidth / width;         }          options.insamplesize = insamplesize;         options.injustdecodebounds = false;         app.bm = bitmapfactory.decodefile(cursor.getstring(colindex), options);         system.io.memorystream mem = new system.io.memorystream();         app.bm.compress(bitmap.compressformat.png, 100, mem);         //byte[] bytearray = mem.toarray();         //_imageview.setimagebitmap(app.bm);          var temp = new imageview(this);         temp.setimagebitmap(app.bm);         app.bm = null;         gc.collect();          alertdialog.builder builder = new alertdialog.builder(this);         builder.settitle("preview");                     builder.setview(temp);         builder.setcancelable(false);         builder.setpositivebutton("cancel", (senderalert, args) =>          {         });         builder.setnegativebutton("delete?", (senderalert, args) =>         {              java.lang.object toremove = myfilelistadapter.getitem(e.position);             myfilelistadapter.remove(toremove);             myfilelistadapter.notifydatasetchanged();             setlistviewheightbasedonchildren(listviewfiles);             listviewfiles.itemclick -= clickhandler;          });          builder.show();     } 

i've encountered these problems cannot figure out until now.

  1. for instance added/imported (from gallery) 3 images, 3 rows in listview. if click item, 3 dialogbox appears well, same photos (of particular item). meaning, dialogbox appears after clicking cancel, one, , one.

  2. delete button works if there more 1 row or item in listview. if there's 1 , delete it, rest of controls/tools below listview gone. in case, have textviews, button, etc. below listview after deleting row, these deleted well.

i'd appreciate or suggestion because i've been trying solve 2 days. thank you.


Comments

Popular posts from this blog

sql - invalid in the select list because it is not contained in either an aggregate function -

Angularjs unit testing - ng-disabled not working when adding text to textarea -

How to start daemon on android by adb -