大家好,我想在我的应用程序中显示图像/视频缩略图。我使用以下代码检索缩略图并在适配器中列出它们。以下是代码
public class ImageAdapter extends BaseAdapter {
private Context context;
private final String[] VideoValues;
public ImageAdapter(Context context, String[] VideoValues) {
this.context = context;
this.VideoValues = VideoValues;
}
public View getView(int position, View convertView, ViewGroup parent) {
System.out.println("***********In getView************");
LayoutInflater inflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View gridView;
if (convertView == null) {
gridView = new View(context);
// get layout from gridlayout.xml
gridView = inflater.inflate(R.layout.gridlayout, null);
// set value into textview
TextView textView = (TextView) gridView
.findViewById(R.id.grid_item_label);
textView.setText(fileList[position]);
System.out.println("value of fileList[position]" + fileList[0]);
// set image
ImageView imageThumbnail = (ImageView) gridView
.findViewById(R.id.grid_item_image);
Bitmap bmThumbnail;
System.out
.println(">>>>>>>>>>>>>>>>>>>>>>>>>>>> file path>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"
+ fileList[position]);
bmThumbnail = ThumbnailUtils.createVideoThumbnail(FILE_PATH
+ fileList[position],
MediaStore.Video.Thumbnails.MINI_KIND);
if (bmThumbnail != null) {
System.out
.println(">>>>>>>>>>>>>>>>>>>>>>>>>>>> THUMB NAIL>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");
imageThumbnail.setImageBitmap(bmThumbnail);
} else {
System.out
.println(">>>>>>>>>>>>>>>>>>>>>>>>>>>>NO THUMB NAIL>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");
}
} else {
gridView = (View) convertView;
}
return gridView;
}
public int getCount() {
// return 0;
return VideoValues.length;
}
public Object getItem(int position) {
return null;
}
public long getItemId(int position) {
return 0;
}
}
}
它适用于三星 Galaxy Tab 10.1 中的图像和视频,但它不适用于 acer iconia A501。对此有任何想法。
两者都在运行 HoneyComb。
Rgds,