BaseAdapter使用

ListView或者GridView中我们常常用到了BaseAdapter,下面一个例子来说明BaseAdapter是在ListView或者GridView中是如何使用的,如下:

public class TransactionAdapter extends BaseAdapter {

private List listList;

private Context mContext;

public TransactionAdapter(List listList,Context mContext) {

this.listList = listList;

this.mContext = mContext;

}

@Override

public intgetCount() {

return listList.size();

}

@Override

public Object getItem(intposition) {

return listList.get(position);

}

@Override

public long getItemId(intposition) {

Log.d("tag",position+"");

return position;

}

@Override

public View getView(int position,View convertView,ViewGroup parent) {

ViewHolder viewHolder;

if(convertView ==null) {

convertView = LayoutInflater.from(mContext).inflate(R.layout.item_transaction_list,parent, false);

viewHolder = new ViewHolder();

viewHolder.tv_item_country= (TextView) convertView.findViewById(R.id.tv_item_country);

viewHolder.tv_item_btc= (TextView) convertView.findViewById(R.id.tv_item_btc);

viewHolder.tv_item_parities= (TextView) convertView.findViewById(R.id.tv_item_parities);

convertView.setTag(viewHolder);

}else{

viewHolder = (ViewHolder) convertView.getTag();

}

if(listList!=null) {

Log.i("TAG---",listList.size()+"");

ABean aBean =listList.get(position);

if(aBean!=null){

viewHolder.tv_item_country.setText(aBean.getName());

viewHolder.tv_item_parities.setText(aBean.getBankConversionPri());

viewHolder.tv_item_btc.setText(aBean.getFBuyPri());

}}

return convertView;

}

public class ViewHolder {

public TextViewtv_item_country,tv_item_btc,tv_item_parities;

}}

你可能感兴趣的:(BaseAdapter使用)