真实的国产乱ⅩXXX66竹夫人,五月香六月婷婷激情综合,亚洲日本VA一区二区三区,亚洲精品一区二区三区麻豆

成都創(chuàng)新互聯(lián)網(wǎng)站制作重慶分公司

優(yōu)化SimpleAdapter適配器加載效率的方法

在主Activity中:

成都創(chuàng)新互聯(lián)公司是專業(yè)的鹽城網(wǎng)站建設(shè)公司,鹽城接單;提供網(wǎng)站建設(shè)、網(wǎng)站制作,網(wǎng)頁設(shè)計(jì),網(wǎng)站設(shè)計(jì),建網(wǎng)站,PHP網(wǎng)站建設(shè)等專業(yè)做網(wǎng)站服務(wù);采用PHP框架,可快速的進(jìn)行鹽城網(wǎng)站開發(fā)網(wǎng)頁制作和功能擴(kuò)展;專業(yè)做搜索引擎喜愛的網(wǎng)站,專業(yè)的做網(wǎng)站團(tuán)隊(duì),希望更多企業(yè)前來合作!

listview=(ListView)findViewById(R.id.listview);getData();

//為list添加數(shù)據(jù)overrideSimpleAdapter=new OverrideSimpleAdapter(getContext(),list,R.layout.list_item_layout,       

new String[]{"num","word","translates"},       

new int[]{R.id.tv_num,R.id.tv_word,R.id.tv_translates});

listview.setAdapter(overrideSimpleAdapter);

重寫SimpleAdapter:/**
 * Created by KewenC on 2017/1/26.
 */

public class OverrideSimpleAdapter extends SimpleAdapter {
  /**
   * Constructor
   *
   * @param context The context where the View associated with this SimpleAdapter is running
   * @param data   A List of Maps. Each entry in the List corresponds to one row in the list. The
   *         Maps contain the data for each row, and should include all the entries specified in
   *         "from"
   * @param resource Resource identifier of a view layout that defines the views for this list
   *         item. The layout file should include at least those named views defined in "to"
   * @param from   A list of column names that will be added to the Map associated with each
   *         item.
   * @param to    The views that should display column in the "from" parameter. These should all be
   *         TextViews. The first N views in this list are given the values of the first N columns
   */

  private LayoutInflater mInflater;
  private ArrayList> list;
  private int mResource;
  private int[] mTo;
  private String[] mFrom;

  public OverrideSimpleAdapter(Context context, ArrayList> data, int resource, String[] from, int[] to) {
    super(context, data, resource, from, to);
    this.list=data;
    this.mInflater = LayoutInflater.from(context);
    this.mResource = resource;
    this.mFrom = from;
    this.mTo = to;
  }

  @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) {
      holder = new ViewHolder();
      // 通過LayoutInflater實(shí)例化布局
      convertView = mInflater.inflate(mResource, null);
//      holder.img = (ImageView) convertView.findViewById(R.id.imageView);
      holder.num = (TextView) convertView.findViewById(mTo[0]);
      holder.word = (TextView) convertView.findViewById(mTo[1]);
      holder.translates = (TextView) convertView.findViewById(mTo[2]);
      convertView.setTag(holder);
    } else {
      // 通過tag找到緩存的布局
      holder = (ViewHolder) convertView.getTag();
    }
    // 設(shè)置布局中控件要顯示的視圖
//    holder.img.setBackgroundResource(R.drawable.ic_launcher);
    holder.num.setText(list.get(position).get(mFrom[0]).toString());// mFrom[0]為“num”Key
    holder.word.setText(list.get(position).get(mFrom[1]).toString());
    holder.translates.setText(list.get(position).get(mFrom[2]).toString());
    return convertView;
  }

  public final class ViewHolder {
//    public ImageView img;
    public TextView num;
    public TextView word;
    public TextView translates;
  }
}

以上這篇優(yōu)化SimpleAdapter適配器加載效率的方法就是小編分享給大家的全部內(nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持創(chuàng)新互聯(lián)。


文章標(biāo)題:優(yōu)化SimpleAdapter適配器加載效率的方法
鏈接地址:http://weahome.cn/article/gcjoco.html

其他資訊

在線咨詢

微信咨詢

電話咨詢

028-86922220(工作日)

18980820575(7×24)

提交需求

返回頂部