delete image from sd card in android -


i try select images sd card,specific folder , show in gridview successfully.i have 1 problem.in gridview onclicklistener want delete image position.strange situation.file deleted in folder ,but gridview still showing images

    private void fetchgalleryimages() {     uri mimageuri = mediastore.images.media.external_content_uri;     final string[] columns = {mediastore.images.media.data, mediastore.images.media.date_added};     cursor imagecursor = getcontentresolver().query(mimageuri, columns, mediastore.images.media.data + " ? ", new string[]{"%/download/new folder%"}, null);     galleryimageurls = new arraylist<>();     (int = 0; < imagecursor.getcount(); i++) {         imagecursor.movetoposition(i);         int datacolumnindex = imagecursor.getcolumnindex(mediastore.images.media.data);//get column index         galleryimageurls.add(imagecursor.getstring(datacolumnindex));//get image column index         log.e("array path", galleryimageurls.get(i));     } } private void setupgridview() {      imagesadapter = new gridview_adapter(customgallery_activity.this, galleryimageurls, true);     galleryimagesgridview.setadapter(imagesadapter);     galleryimagesgridview.setonitemclicklistener(new adapterview.onitemclicklistener() {         @override         public void onitemclick(adapterview<?> parent, view view, int position, long id) {             file file = new file(galleryimageurls.get(position));             if (file.exists())             {                 file.delete();                 imagesadapter = new gridview_adapter(customgallery_activity.this, galleryimageurls, true);                 galleryimagesgridview.setadapter(imagesadapter);             }          }     }); } 

sorry misateked.i added line in onclick

 galleryimageurls.remove(position); 

i closed app , run again have same problem.. want update gridview

this correct answer.i solved myself

 private void setupgridview() {      imagesadapter = new gridview_adapter(customgallery_activity.this, galleryimageurls, true);     galleryimagesgridview.setadapter(imagesadapter);     galleryimagesgridview.setonitemclicklistener(new adapterview.onitemclicklistener() {         @override         public void onitemclick(adapterview<?> parent, view view, int position, long id) {             file file = new file(galleryimageurls.get(position));             if (file.exists())             {                 file.delete();                 deletefilefrommediamanager(galleryimageurls.get(position));                 galleryimageurls.remove(position);                 imagesadapter = new gridview_adapter(customgallery_activity.this, galleryimageurls, true);                 galleryimagesgridview.setadapter(imagesadapter);             }          }     }); }  private void deletefilefrommediamanager(string path) {     try {         mediascannerconnection.scanfile(customgallery_activity.this, new string[] { path },                 null, new mediascannerconnection.onscancompletedlistener() {                     public void onscancompleted(string path, uri uri) {                         customgallery_activity.this.getcontentresolver()                                 .delete(uri, null, null);                     }                 });     } catch (exception e) {         e.printstacktrace();     }  } 

Comments

Popular posts from this blog

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -