91超碰碰碰碰久久久久久综合_超碰av人澡人澡人澡人澡人掠_国产黄大片在线观看画质优化_txt小说免费全本

溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

優化SimpleAdapter適配器加載效率的方法

發布時間:2020-10-10 13:43:25 來源:腳本之家 閱讀:135 作者:jingxian 欄目:移動開發

在主Activity中:

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

//為list添加數據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<Map<String, Object>> list;
  private int mResource;
  private int[] mTo;
  private String[] mFrom;

  public OverrideSimpleAdapter(Context context, ArrayList<Map<String, Object>> 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實例化布局
      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();
    }
    // 設置布局中控件要顯示的視圖
//    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;
  }
}

以上這篇優化SimpleAdapter適配器加載效率的方法就是小編分享給大家的全部內容了,希望能給大家一個參考,也希望大家多多支持億速云。

向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

沂源县| 邻水| 福鼎市| 宁武县| 界首市| 浙江省| 洞头县| 即墨市| 凌海市| 司法| 子洲县| 蓝山县| 赤峰市| 定日县| 荣昌县| 望江县| 广东省| 静海县| 会昌县| 祁连县| 固阳县| 德兴市| 诏安县| 潜江市| 慈利县| 湖南省| 万盛区| 铜川市| 兴义市| 邛崃市| 郯城县| 界首市| 天峻县| 平利县| 宾阳县| 上饶市| 额济纳旗| 榆树市| 大洼县| 吉隆县| 汝阳县|