涉及到幾個簡單的知識點:
1.使用ContentProvider管理多媒體內容:
MediaStore.Images.Media.EXTERNAL_CONTENT_URI 外部存儲器圖片文件內容的uri
MediaStore.Images.Media.INTERNAL_CONTENT_URI 內部存儲器圖片文件內容的uri
若把Images換成Audio或Video,則表示音頻或視頻
Cursor cursor = getContentResolver().query(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, null, null, null, null);
該句獲取sd卡上的所有圖片信息
while(cursor.moveToNext()){
String ImageName = cursor.getString(cursor.getColumnIndex(MediaStore.Images.Media.DISPLAY_NAME)); //獲取圖片的名字
String ImagePath = cursor.getString(cursor.getColumnIndex(MediaStore.Images.Media.DATA));
//獲取圖片的路徑
String ImageSize = cursor.getString(cursor.getColumnIndex(MediaStore.Images.Media.SIZE));
//獲取圖片的大小
}
2.使用simpleAdapter實現列表
其構造函數如下
public SimpleAdapter (Context context, List<? extends Map<String, ?>> data, int resource, String[] from, int[] to)
contextSimpleAdapter關聯的View的運行環境
data 一個Map組成的List。在列表中的每個條目對應列表中的一行,每一個map中應該 包含所有在from參數中指定的鍵
resource 一個定義列表項的佈局文件的資源ID。佈局文件將至少應包含那些在to中定義 了的ID
from 一個將被添加到Map映射上的鍵名
to 將綁定數據的視圖的ID,跟from參數對應,這些應該全是TextView
具體代碼如下:
List<Map<String , Object>> ImageList = new ArrayList<Map<String,Object>>();
for(int i=0;i<ImageNameList.size();i++){
Map<String , Object> ImageMap = new HashMap<String, Object>();
ImageMap.put("ImageName", ImageNameList.get(i));
ImageMap.put("ImagePath", ImagePathList.get(i));
ImageMap.put("ImageSize", ImageSizeList.get(i));
ImageList.add(ImageMap);
}
AllImage.setAdapter(new SimpleAdapter(this,ImageList,R.layout.activity_main,
new String[]{"ImageName","ImagePath","ImageSize"},new int[]{R.id.ImageName,R.id.ImagePath,R.id.ImageSize}));
最終如上
鏈接呈上,需要的朋友可以下來看看
http://download.csdn.net/detail/liuweikai2012/8542677