简体   繁体   English

使用OnItemLongClick事件从图库中删除图像

[英]delete image from gallery with OnItemLongClick event

I want to know how can I use OnItemLongClickListener event to delete an image from gallery? 我想知道如何使用OnItemLongClickListener事件从图库中删除图像吗?

I don't know how can I find the url or another detail about the image from this event in order to delete it. 我不知道如何从此事件中找到该图像的URL或其他详细信息以将其删除。

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. 感谢帮助。

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 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);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM