listview与自定义适配器没有显示缩略图...而是显示不同的picture2

时间:2016-12-31 11:15:41

标签: android listview adapter

              CustomVideoAdapter VideolistAdapter = new CustomVideoAdapter(this, songs);
                audiolistview.setAdapter(VideolistAdapter);
                audiolistview.setOnItemClickListener(new AdapterView.OnItemClickListener() {
                    @Override
                    public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
                        music_column_index = musicCursor.getColumnIndexOrThrow(MediaStore.Video.Media.DATA);
                        cursorPoristion = i;
                        musicCursor.moveToPosition(i);
                        String filename = musicCursor.getString(music_column_index);
                        mediaController.setAnchorView(videoView);
                        mediaController.setMediaPlayer(videoView);
                        mediaController.setEnabled(true);
                        videoView.setVideoPath(filename);
                        videoView.setMediaController(mediaController);
                        videoView.start();
                        videoView.setZOrderOnTop(true);
                    }
                });

// customAdapter for list

public class CustomVideoAdapter extends BaseAdapter {
Context context;
List<AudioModel> rowItems;


 public CustomVideoAdapter(Context context, List<AudioModel> items) {
    this.context = context;
    this.rowItems = items;
}

/*private view holder class*/
private class ViewHolder {
    ImageView imageView;
    TextView txtTitle;
    TextView txtDesc;
}



      public View getView(int position, View convertView, ViewGroup parent) {
    ViewHolder holder = null;

    LayoutInflater mInflater = (LayoutInflater)
            context.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
    if (convertView == null) {
        convertView = mInflater.inflate(R.layout.video_list, null);
        holder = new ViewHolder();
        holder.txtTitle = (TextView) convertView.findViewById(R.id.title);
        holder.imageView = (ImageView) convertView.findViewById(R.id.icon);
        convertView.setTag(holder);
    }
    else {
        holder = (ViewHolder) convertView.getTag();
    }

    AudioModel rowItem = (AudioModel) getItem(position);
    String path=rowItem.getaPath();
    Bitmap thumb = ThumbnailUtils.createVideoThumbnail(path,
            MediaStore.Images.Thumbnails.MINI_KIND);

    holder.txtTitle.setText(rowItem.getaName());
    holder.imageView.setImageBitmap(thumb);

    return convertView;
}

@Override
public int getCount() {
    return rowItems.size();
}

@Override
public Object getItem(int position) {
    return rowItems.get(position);
}

@Override
public long getItemId(int position) {
    return rowItems.indexOf(getItem(position));
}

}

1.运行此应用程序代码时,我无法获取视频文件列表的缩略图,视频未显示但声音正在播放。

2.我已经设置了两个不同的自定义适配器来显示视频列表和音频列表...我在这里遇到的问题是视频列表未按预期从视频列表布局显示...

0 个答案:

没有答案