在做android开发过程中往往用到适配器,最具扩展性的适配器是BaseAdapter,可以根据实际需要往里面同时添加各种类型的数据。他的使用方法最简单的形式如下:
第一种:
public class MyAdapter extends BaseAdapter {ViewHold viewHold;
class ViewHold {
TextView countTextView;
TextView lapTimeTextView;
TextView totalTimeTextView;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
// ViewHold viewHold;
if (convertView == null) {
convertView = LayoutInflater.from(getActivity()).inflate(
R.layout.list_item_view, null);
viewHold = new ViewHold();
viewHold.countTextView = (TextView) convertView
.findViewById(R.id.countTextView);
viewHold.lapTimeTextView = (TextView) convertView
.findViewById(R.id.lapTimeTextView);
viewHold.totalTimeTextView = (TextView) convertView
.findViewById(R.id.totalTimeTextView);
convertView.setTag(viewHold);
} else {
viewHold = (ViewHold) convertView.getTag();
}
viewHold.countTextView.setText(MainFragment.listItemBeans
.get(position).count);
viewHold.lapTimeTextView.setText(MainFragment.listItemBeans
.get(position).lapTime);
viewHold.totalTimeTextView.setText(MainFragment.listItemBeans
.get(position).totalTime);
return convertView;
}
@Override
public long getItemId(int position) {
// TODO Auto-generated method stub
return position;
}
@Override
public Object getItem(int position) {
// TODO Auto-generated method stub
return MainFragment.listItemBeans.get(position);
}
@Override
public int getCount() {
// TODO Auto-generated method stub
return MainFragment.listItemBeans.size();
}
};