自定义Adapter写法记录
程序员文章站
2022-07-15 09:16:04
...
package com.example.coolvidaoplayer;
import java.util.List;
import java.util.Map;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;
public class VidaoListAdapter extends BaseAdapter {
private LayoutInflater videoListInflater;
private List<Map<String,Object>>videoList;
public VidaoListAdapter(Context context,List<Map<String,Object>>list)
{
this.videoListInflater=LayoutInflater.from(context);
this.videoList=list;
}
static class ViewHolder{
ImageView ivVideoThumbnail;
TextView tvVideoName;
TextView tvVideoSize;
}
@Override
public int getCount() {
// TODO Auto-generated method stub
if(videoList!=null)
{
return videoList.size();
}else
return 0;
}
@Override
public Object getItem(int pos) {
// TODO Auto-generated method stub
return videoList.get(pos);
}
@Override
public long getItemId(int id) {
// TODO Auto-generated method stub
return id;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
ViewHolder videoHolder=null;
if(convertView==null)
{
videoHolder=new ViewHolder();
convertView=videoListInflater.inflate(R.layout.list_item_vidaoinfo, null);
videoHolder.ivVideoThumbnail=(ImageView)convertView.findViewById(R.id.iv_vidao_thumbnail);
videoHolder.tvVideoName=(TextView)convertView.findViewById(R.id.tv_vidao_name);
videoHolder.tvVideoSize=(TextView)convertView.findViewById(R.id.tv_vidao_size);
videoHolder.ivVideoThumbnail.setBackgroundResource((Integer)videoList.get(position).get("videothumbnail"));
videoHolder.tvVideoName.setText((String)videoList.get(position).get("videoname"));
videoHolder.tvVideoSize.setText((String)videoList.get(position).get("videosize"));
convertView.setTag(videoHolder);
}
else
{
videoHolder=(ViewHolder)convertView.getTag();
}
return convertView;
}
}
上一篇: 自定义ListView的写法
下一篇: 批量修改数据库表字段的编码
推荐阅读