0

I want to know how can I use OnItemLongClickListener event to delete an image from gallery?

I don't know how can I find the url or another detail about the image from this event in order to delete it.

this is What I did so far (* I already have a gallery with images inside) : First I connect the gallery to the event :

gallery.setOnItemLongClickListener(OnLongClickGallery);

Then I want to ask the user if he sure that he want to delete the image and in the same time save the data from the selected item:

private OnItemLongClickListener OnLongClickGallery = new OnItemLongClickListener() {

    @Override
    public boolean onItemLongClick(AdapterView<?> arg0, View arg1,
            int arg2, long arg3) {
        //How I get the desired data here?
        showPopupMenu(arg1);// Show pop up list 
        return false;
    }
};

Thanks for help.

user2235615
  • 1,513
  • 3
  • 17
  • 37

1 Answers1

1

I think you can take help from

  • How to get a image and implementing click listener

http://androidsamples.blogspot.in/2009/06/how-to-display-thumbnails-of-images.html

  • How to delete a image from content provider

Deleting a gallery image after camera intent photo taken

ContentResolver cr = getContentResolver();
                     cr.delete(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, 
                        BaseColumns._ID + "=" + c.getString(3), null);

EDIT: To get path from content provider

image_path_index = cursor.getColumnIndex(MediaStore.Images.Media.DATA)
path[i] = cursor.getString(image_path_index);
Community
  • 1
  • 1
Sunny
  • 1,441
  • 2
  • 13
  • 22
  • But I need the path or the file name. How I get this? – user2235615 Apr 10 '13 at 09:03
  • one of the column in content provider is path Images.ImageColumns.DATA is the path [source](http://stackoverflow.com/questions/8737054/how-to-get-path-by-mediastore-images-media) – Sunny Apr 10 '13 at 09:50
  • check the edited comment and check the link mentioned in above comment about how to create a cursor – Sunny Apr 10 '13 at 10:03