android怎么样从GridView控件通过onItemClick听者获得图像路径 [英] android How to get image path from GridView through onItemClick listener

查看:82
本文介绍了android怎么样从GridView控件通过onItemClick听者获得图像路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

陷了一下,因为我不明白如何从路径
图片我点击GridView中。

这是监听的问题,因为我是从对SD卡的文件夹与图像加载GridView的。

 公共无效onItemClick(适配器视图父母,视图V,INT位置,长的ID)

我只能看到例如如何使用时,GridView控件从资源加载的位置。

谁能给我一个提示如何做到这一点。
即时阅读并尝试这种

 的String [] =投影{MediaStore.Images.Media.DATA};
光标光标= managedQuery(MediaStore.Images.Thumbnails.EXTERNAL_CONTENT_URI,
投影,
空值,
空值,
空值)

但是,这将使我从SD卡根目录的所有图像。
我的文件夹SD卡/ PTPPservice

我将从这里发送意图展现像图片:

 意向意图=新意图(getApplicationContext(),ViewImage.class);
      intent.putExtra(文件名的ImagePath);
      startActivity(意向);


解决方案

找到了解决办法,所以我回答我自己quesion。
该orgPath是一个字符串我增加和图像的loadind过程中保存的路径

 公共无效onItemClick(适配器视图<>母公司,视图V,INT位置,长的id){    ImageAdapter I =(ImageAdapter)parent.getAdapter();
    LoadedImage L =(LoadedImage)i.getItem(位置);    意向意图=新意图(getApplicationContext(),ViewImage.class);
    intent.putExtra(文件名,l.orgPath);
    startActivity(意向);
    返回;}

Got stuck a bit since i cannot understand how to get the path from a picture i click in the GridView.

This listener is the problem since i load the GridView with images from a folder on the sdcard.

public void onItemClick(AdapterView parent, View v, int position, long id)

I can only see example on how to use the "position" when the GridView is loaded from resources.

Can anyone give me a hint how to do this. Im reading and trying this

String[] projection = {MediaStore.Images.Media.DATA};
Cursor cursor = managedQuery( MediaStore.Images.Thumbnails.EXTERNAL_CONTENT_URI,
projection,
null, 
null, 
null)

But that will give me all images from sdcard root. My folder is "sdcard/PTPPservice"

I will from here send an intent to show the image like:

      Intent intent = new Intent(getApplicationContext(), ViewImage.class);
      intent.putExtra("filename", imagePath);
      startActivity(intent);

解决方案

Found the solution, so i answer my own quesion. The orgPath is a string i added and saves the path during loadind of images

public void onItemClick(AdapterView<?> parent, View v, int position, long id) {    

    ImageAdapter i = (ImageAdapter)parent.getAdapter();
    LoadedImage l = (LoadedImage)i.getItem(position);

    Intent intent = new Intent(getApplicationContext(), ViewImage.class);
    intent.putExtra("filename", l.orgPath);
    startActivity(intent);
    return;

}

这篇关于android怎么样从GridView控件通过onItemClick听者获得图像路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆