Android 阅读ArrayList<;字符串>;将URI导入coverflow应用程序,而不是R.drawables
我正在将MediaStore.Images.Media.DATA字符串从ArrayList读取到一个数组中,这样我就可以使用SD卡中的图像,而不是coverflow gallery应用程序的R.drawable文件夹中的图像。撞到了一堵砖墙。与读取整数类型与字符串类型的图像信息的问题 能够从SD卡的所有图像中获取URI到arraylist,但不知道下一步要做什么 是否值得继续使用这种方法,还是最好放弃这种方法,尝试另一种方法来完成将此coverflow应用程序的图像源从R.drawables文件夹更改为SD卡的任务 这就是我所做的 首先,以下是它使用数组从android中的R.drawable文件夹获取图像的方式:Android 阅读ArrayList<;字符串>;将URI导入coverflow应用程序,而不是R.drawables,android,android-contentprovider,sd-card,coverflow,Android,Android Contentprovider,Sd Card,Coverflow,我正在将MediaStore.Images.Media.DATA字符串从ArrayList读取到一个数组中,这样我就可以使用SD卡中的图像,而不是coverflow gallery应用程序的R.drawable文件夹中的图像。撞到了一堵砖墙。与读取整数类型与字符串类型的图像信息的问题 能够从SD卡的所有图像中获取URI到arraylist,但不知道下一步要做什么 是否值得继续使用这种方法,还是最好放弃这种方法,尝试另一种方法来完成将此coverflow应用程序的图像源从R.drawables文件
public class ImageAdapter extends BaseAdapter {
int mGalleryItemBackground;
private Context mContext;
private FileInputStream fis;
// private Integer[] mImageIds = {
// R.drawable.pic01,
// R.drawable.pic02,
// R.drawable.pic03,
// R.drawable.pic04,
// R.drawable.pic05,
// R.drawable.pic06,
// R.drawable.pic07,
// R.drawable.pic08,
// R.drawable.pic09
// };
private ImageView[] mImages;
我的想法是使用光标从SD卡中读取URI,如“//mnt/sdcard/pic01.png”,并使用这些地址,而不是数组中R.drawable中的地址,如数组中的“R.drawable.pic02”
这就是我所做的,这部分工作没有任何问题:
我从SD卡上的图像中获取了所有URI,并将它们存储在arrayList中,到目前为止,一切都很正常。通过使用Toast在活动屏幕上显示加载的uri,我验证了它可以完美地工作
ArrayList<String> list1 = new ArrayList<String>();
String[] proj = {MediaStore.Images.Media.DATA};
Cursor cur = getContentResolver().query(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, proj, null, null, null);
if (cur.getCount() > 0) {
while (cur.moveToNext()) {
String pic = cur.getString(cur.getColumnIndex(MediaStore.Images.Media.DATA));
list1.add(pic);
// Toast.makeText(CoverFlowExample.this, "data name: " + pic, Toast.LENGTH_SHORT).show();
// Log.d("TAG", "ID: " + pic);
}
}
cur.close();
下面是应用程序getview部分的其余代码:我现在正试图找出下一步要做什么
public View getView(int position, View convertView, ViewGroup parent) {
//Use this code if you want to load from resources from external source
ImageView i = new ImageView(mContext);
// this method is what someone suggested to use but i don't know how to use this, what do i put for "image" and how to read URIs from arrayList to this?
i.setImageBitmap(BitmapFactory.decodeFile("image_" + position));
// this works for reading in only one image from the SD card into the coverflow app
i.setImageBitmap(BitmapFactory.decodeFile("/mnt/sdcard/pic04.png"));
// when getting from R.drawable images --> i.setImageResource(mImageIds[position]);
i.setLayoutParams(new CoverFlow.LayoutParams(130, 130));
i.setScaleType(ImageView.ScaleType.MATRIX);
return i;
//return mImages[position];
}
由于已经有了URI/文件系统路径,因此可以使用
Drawable
的createFrom*
方法之一加载它
mImageIds[t]= list1.get(t);
public View getView(int position, View convertView, ViewGroup parent) {
//Use this code if you want to load from resources from external source
ImageView i = new ImageView(mContext);
// this method is what someone suggested to use but i don't know how to use this, what do i put for "image" and how to read URIs from arrayList to this?
i.setImageBitmap(BitmapFactory.decodeFile("image_" + position));
// this works for reading in only one image from the SD card into the coverflow app
i.setImageBitmap(BitmapFactory.decodeFile("/mnt/sdcard/pic04.png"));
// when getting from R.drawable images --> i.setImageResource(mImageIds[position]);
i.setLayoutParams(new CoverFlow.LayoutParams(130, 130));
i.setScaleType(ImageView.ScaleType.MATRIX);
return i;
//return mImages[position];
}