大家好我想在我的应用程序中显示图像/视频缩略图。我使用以下代码检索缩略图并将它们列在适配器中。 以下是代码
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标签10.1中的图像和视频,但它不适用于acer iconia A50。对此有所了解。
两者都在运行HoneyComb。
RGDS,
答案 0 :(得分:0)
我希望这对你有所帮助。只需将其调整到您的应用程序:
View view = convertView;
if (convertView == null)
view = inflater.inflate(R.layout.grid_item_layout, null);
ImageView image = (ImageView) view.findViewById(R.id.image);
TextView textView = (TextView) view.findViewById(R.id.date);
final BitmapFactory.Options options = new BitmapFactory.Options();
options.inSampleSize = 8;
String filePath = fileList.get(position).getFilePath();
String dateTaken = fileList.get(position).getDateTaken();
Long type = fileList.get(position).getType();
Bitmap bitmap = null;
if(type == MediaStore.Files.FileColumns.MEDIA_TYPE_IMAGE)
bitmap = BitmapFactory.decodeFile(filePath, options);
else if(type == MediaStore.Files.FileColumns.MEDIA_TYPE_VIDEO)
bitmap = ThumbnailUtils.createVideoThumbnail(filePath, 0);
image.setImageBitmap(bitmap);
textView.setText(dateTaken);