content: package com.hensen.greendaodemo.Adapter;
  
  import android.content.Context;
  import android.graphics.Paint;
  import android.view.LayoutInflater;
  import android.view.View;
  import android.view.ViewGroup;
  import android.widget.BaseAdapter;
  import android.widget.ImageView;
  import android.widget.TextView;
  
  import com.hensen.greendaodemo.R;
  import com.hensen.greendaodemo.Bean.Shop;
  import com.lidroid.xutils.BitmapUtils;
  
  import java.util.List;
  
  /**
   * Created by handsome on 2016/4/8.
   */
  public class ShopListAdapter extends BaseAdapter {
  
      private List<Shop> list;
      //使用XUtils2包的图片加载模块
      private BitmapUtils bitmapUtils;
      private LayoutInflater mInflater;
  
      public ShopListAdapter(Context context, List<Shop> list) {
          this.list = list;
          mInflater = LayoutInflater.from(context);
          bitmapUtils = new BitmapUtils(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) {
          if (convertView == null) {
              convertView = mInflater.inflate(R.layout.adapter_shop_list, null);
          }
          ViewHolder holder = getViewHolder(convertView);
          Shop shop = list.get(position);
          bitmapUtils.display(holder.iv_shop, shop.getImage_url());
          holder.tv_name.setText(shop.getName());
          holder.tv_price.setText(shop.getPrice() + "");
          holder.tv_price_discount.setPaintFlags(Paint.STRIKE_THRU_TEXT_FLAG);
          holder.tv_sell_num.setText("已售" + shop.getSell_num() + "件");
          return convertView;
      }
  
      /**
       * 获得控件管理对象
       *
       * @param view
       * @return
       */
      private ViewHolder getViewHolder(View view) {
          ViewHolder holder = (ViewHolder) view.getTag();
          if (holder == null) {
              holder = new ViewHolder(view);
              view.setTag(holder);
          }
          return holder;
      }
  
      /**
       * 控件管理类
       */
      private class ViewHolder {
          private TextView tv_name, tv_price, tv_price_discount, tv_sell_num;
          private ImageView iv_shop;
  
          ViewHolder(View view) {
              tv_name = (TextView) view.findViewById(R.id.tv_name);
              tv_price = (TextView) view.findViewById(R.id.tv_price);
              tv_price_discount = (TextView) view.findViewById(R.id.tv_price_discount);
              tv_sell_num = (TextView) view.findViewById(R.id.tv_sell_num);
              iv_shop = (ImageView) view.findViewById(R.id.iv_shop);
          }
      }
  }
  