80,351
社区成员
发帖
与我相关
我的任务
分享
/**
* 加载数据
*/
private void AddData()
{
List<Map<String, Object>> list = getData();
SimpleAdapter listItemAdapter = new SimpleAdapter(this, list, R.layout.listview,
new String[]{"pic","title","info"},
new int[]{R.id.list_pic,R.id.list_title,R.id.list_info});
listView.setAdapter(listItemAdapter);
listView.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3)
{
Intent intent = new Intent(MediaListActivity.this,MediaActivity.class);
intent.putExtra("path", mediaFiles.get(arg2).getPath());
startActivity(intent);
}
});
}
/**
* 获取数据
* @return
*/
private List<Map<String, Object>> getData()
{
List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
mediaFiles = MediaFile.getInfo();
for (int i = 0; i < mediaFiles.size(); i++) {
MediaFile mediafile = mediaFiles.get(i);
String filePath = mediafile.getPath();
Map<String, Object> map = new HashMap<String, Object>();
if (!new File(filePath).exists()) {
continue;
}
Bitmap mediaThumb;
if(filePath.endsWith("mp4"))
{
mediaThumb = getVideoThumbnail(filePath, 72, 72, MediaStore.Images.Thumbnails.MICRO_KIND);
}
else {
mediaThumb = getImageThumbnail(filePath, 72, 72);
}
map.put("pic", mediaThumb);
map.put("title", mediafile.getTitle());
map.put("info", mediafile.getShotTime());
list.add(map);
}
return list;
}
private void bindView(int position, View view) {
final Map dataSet = mData.get(position);
if (dataSet == null) {
return;
}
final ViewBinder binder = mViewBinder;
final String[] from = mFrom;
final int[] to = mTo;
final int count = to.length;
for (int i = 0; i < count; i++) {
final View v = view.findViewById(to[i]);
if (v != null) {
final Object data = dataSet.get(from[i]);
String text = data == null ? "" : data.toString();
if (text == null) {
text = "";
}
boolean bound = false;
if (binder != null) {
bound = binder.setViewValue(v, data, text);
}
if (!bound) {
if (v instanceof Checkable) {
if (data instanceof Boolean) {
((Checkable) v).setChecked((Boolean) data);
} else if (v instanceof TextView) {
// Note: keep the instanceof TextView check at the bottom of these
// ifs since a lot of views are TextViews (e.g. CheckBoxes).
setViewText((TextView) v, text);
} else {
throw new IllegalStateException(v.getClass().getName() +
" should be bound to a Boolean, not a " +
(data == null ? "<unknown type>" : data.getClass()));
}
} else if (v instanceof TextView) {
// Note: keep the instanceof TextView check at the bottom of these
// ifs since a lot of views are TextViews (e.g. CheckBoxes).
setViewText((TextView) v, text);
} else if (v instanceof ImageView) {
if (data instanceof Integer) {
setViewImage((ImageView) v, (Integer) data);
} else {
setViewImage((ImageView) v, text);
}
} else {
throw new IllegalStateException(v.getClass().getName() + " is not a " +
" view that can be bounds by this SimpleAdapter");
}
}
}
}
}
这里面当控件是ImageView的时候,他只分了两种情况,一种是资源ID,一种是文件地址,我传入的数据是Bitmap类型的数据,在这里当然就当成了文件地址来处理,自然就会有FileNotFoundException。知道了原因,解决方案就呼之欲出了,就是自己重写这个类,增加一种情况当数据类型是Bitmap的时候怎么处理,然后就轻松自在的解决了,代码我就不贴了,因为确实没什么好贴的,找到了原因,解决方案实在不值一提