这是listview中显示视频缩略图的自定义适配器类
我尝试将VideoFetcherTask添加到asyncTask但是滚动缩略图更改继续请帮助我,我也尝试在加载前存储拇指数据,但仍然遇到问题。
public class VideoAdapter extends CursorAdapter {
private Context mContext;
private Cursor mCursor;
public VideoAdapter(Context context, Cursor cursor){
super(context, cursor, 0);
mContext = context;
mCursor = cursor;
}
public void setData (Cursor data){
if (data != null) {
changeCursor(data);
notifyDataSetChanged();
}
}
@Override
public View newView(Context context, Cursor cursor, ViewGroup parent){
return LayoutInflater.from(context).inflate(R.layout.video_item, parent, false);
}
public void bindView(View view, Context context, Cursor cursor){
TextView tvName = (TextView)view.findViewById(R.id.video_display_name);
final ImageView thumbnailView = (ImageView)view.findViewById(R.id.video_thumbnail);
String displayName = cursor.getString(cursor.getColumnIndexOrThrow(
MediaStore.Video.Media.DISPLAY_NAME
));
//todo remove code duplication - already exists in FileChooserActivity
final int column_index = cursor.getColumnIndexOrThrow(MediaStore.Video.Media.DATA);
final String path = cursor.getString(column_index);
final Bitmap thumbnail = ThumbnailUtils.createVideoThumbnail(path, MediaStore.Images.Thumbnails.MINI_KIND);
tvName.setText(displayName);
thumbnailView.setContentDescription(displayName);
thumbnailView.setImageBitmap(thumbnail);
}
}
我这样实施。我在一些权限后给出了null并执行videofetcher异步任务来加载来自设备的所有视频及其工作魅力但是在滚动设备上是高腿
videoAdapter = new VideoAdapter(this, null);
videoList.setAdapter(videoAdapter);
VideoFetcherTask.execute(1,0);
public class VideoFetcherTask extends AsyncTask<Integer, Integer, Cursor>
{
private CursorLoader videoLoader;
String[] projections = {MediaStore.Video.Media._ID,
MediaStore.Video.Media.DATA,
MediaStore.Video.Media.DISPLAY_NAME,
MediaStore.Video.Media.SIZE};
protected void onPreExecute(){
videoLoader = new CursorLoader(FileChooserActivity.this, MediaStore.Video.Media.EXTERNAL_CONTENT_URI, projections,
null, // Return all rows
null, MediaStore.Files.FileColumns.DISPLAY_NAME + " DESC");
}
public Cursor doInBackground(Integer... params){
return videoLoader.loadInBackground();
}
@Override
protected void onPostExecute(Cursor cursor) {
super.onPostExecute(cursor);
videosCursor = cursor;
if (emptyVideoList != null) {
emptyVideoList.setVisibility(View.GONE);
}
videoAdapter.changeCursor(cursor);
videoAdapter.notifyDataSetChanged();
}
}