首页 > 代码库 > 继承BaseAdapter的一个模板
继承BaseAdapter的一个模板
Context context;
private List<String> list;
LayoutInflater inflater;
public XialaDistanceAdapter(Context context,List<String> list){
this.context = context;
this.list = list;
inflater=LayoutInflater.from(context); }
@Override
public int getCount() {
return list.size();
}
@Override
public Object getItem(int position) {
return list.get(position);
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder = null;
if(convertView==null){
convertView = inflater.inflate(R.layout.xialadistance_item, null);
holder = new ViewHolder();
holder.textView =(TextView)convertView.findViewById(R.id.distance);
convertView.setTag(holder);
}
else{
holder=(ViewHolder)convertView.getTag();
}
holder.textView.setText(list.get(position));
return convertView;
}
public static class ViewHolder{
public TextView textView;
}