如何设置setImageResource,我有手机图库图像的URI

时间:2015-07-04 21:37:48

标签: java android gridview imageview

我将来自Gallery的手机图像的所有URI都包含在:

false

其输出是:

for(String item: items) {
    Log.d("Images", item);
}

我想在gridview中填充这些内容。我们可以将Drawable中的静态图像设置为:

07-04 17:30:22.633  11140-11140/com.example.android.HomeWork2 D/Images﹕ /storage/emulated/0/DCIM/Camera/IMG_20150425_131643.jpg
07-04 17:30:22.633  11140-11140/com.example.android.HomeWork2 D/Images﹕ /storage/emulated/0/DCIM/Camera/IMG_20150426_213547.jpg
07-04 17:30:22.633  11140-11140/com.example.android.HomeWork2 D/Images﹕ /storage/emulated/0/DCIM/Camera/IMG_20150426_213646.jpg
07-04 17:30:22.633  11140-11140/com.example.android.HomeWork2 D/Images﹕ /storage/emulated/0/DCIM/Camera/IMG_20150426_221519.jpg
07-04 17:30:22.633  11140-11140/com.example.android.HomeWork2 D/Images﹕ /storage/emulated/0/DCIM/Camera/IMG_20150426_221530.jpg
07-04 17:30:22.633  11140-11140/com.example.android.HomeWork2 D/Images﹕ /storage/emulated/0/DCIM/Camera/IMG_20150426_221544.jpg
07-04 17:30:22.633  11140-11140/com.example.android.HomeWork2 D/Images﹕ /storage/emulated/0/DCIM/Camera/IMG_20150426_221628.jpg
07-04 17:30:22.633  11140-11140/com.example.android.HomeWork2 D/Images﹕ /storage/emulated/0/DCIM/Camera/IMG_20150426_222055.jpg
07-04 17:30:22.633  11140-11140/com.example.android.HomeWork2 D/Images﹕ /storage/emulated/0/DCIM/Camera/IMG_20150426_222533_HDR.jpg
07-04 17:30:22.633  11140-11140/com.example.android.HomeWork2 D/Images﹕ /storage/emulated/0/DCIM/Camera/IMG_20150426_222541_HDR.jpg
07-04 17:30:22.633  11140-11140/com.example.android.HomeWork2 D/Images﹕ /storage/emulated/0/DCIM/Camera/IMG_20150426_222552_HDR.jpg
07-04 17:30:22.633  11140-11140/com.example.android.HomeWork2 D/Images﹕ /storage/emulated/0/DCIM/Camera/IMG_20150426_222637_HDR.jpg
07-04 17:30:22.633  11140-11140/com.example.android.HomeWork2 D/Images﹕ /storage/emulated/0/DCIM/Camera/IMG_20150426_222643_HDR.jpg
07-04 17:30:22.633  11140-11140/com.example.android.HomeWork2 D/Images﹕ /storage/emulated/0/DCIM/Camera/IMG_20150429_205140_HDR.jpg
07-04 17:30:22.633  11140-11140/com.example.android.HomeWork2 D/Images﹕ /storage/emulated/0/DCIM/Camera/IMG_20150429_205148_HDR.jpg

其中:

imageView.setImageResource(mThumbIds[position]);

我的gridview是:

private Integer[] mThumbIds = {
     R.drawable.ic_launcher,R.drawable.ic_launcher
};

我想知道如何动态设置图像,因为我不知道图库中有多少图像及其URI直到运行时。

1 个答案:

答案 0 :(得分:0)

您需要使用适合为您填充网格的适配器。等到你有关于图像的信息,然后适当地填充适配器。可以找到一个很好的教程,展示如何使用网格视图并用图像+文本填充它们here