最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

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

 更新時(shí)間:2017年04月18日 10:00:58   投稿:jingxian  
下面小編就為大家?guī)硪黄獌?yōu)化SimpleAdapter適配器加載效率的方法。小編覺得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧

在主Activity中:

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<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實(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適配器加載效率的方法就是小編分享給大家的全部?jī)?nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。

相關(guān)文章

  • Android 三行代碼實(shí)現(xiàn)高斯模糊效果

    Android 三行代碼實(shí)現(xiàn)高斯模糊效果

    這篇文章主要介紹了Android 三行代碼實(shí)現(xiàn)高斯模糊效果,文章圍繞主題展開詳細(xì)的內(nèi)容介紹,具有一定的參考價(jià)值,需要的小伙伴可以參考一下
    2022-09-09
  • Android PopupWindow實(shí)現(xiàn)左側(cè)彈窗效果

    Android PopupWindow實(shí)現(xiàn)左側(cè)彈窗效果

    這篇文章主要為大家詳細(xì)介紹了Android PopupWindow實(shí)現(xiàn)左側(cè)彈窗效果,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2017-10-10
  • Android自定義view實(shí)現(xiàn)雪花特效實(shí)例代碼

    Android自定義view實(shí)現(xiàn)雪花特效實(shí)例代碼

    實(shí)現(xiàn)雪花的效果其實(shí)也可以通過自定義View的方式來實(shí)現(xiàn)的,而且操作上也相對(duì)簡(jiǎn)單一些,下面這篇文章主要給大家介紹了關(guān)于Android自定義view實(shí)現(xiàn)雪花特效的相關(guān)資料,文中通過實(shí)例代碼介紹的非常詳細(xì),需要的朋友可以參考下
    2022-12-12
  • Android實(shí)現(xiàn)隨機(jī)圓形云標(biāo)簽效果

    Android實(shí)現(xiàn)隨機(jī)圓形云標(biāo)簽效果

    這篇文章主要為大家詳細(xì)介紹了Android實(shí)現(xiàn)隨機(jī)圓形云標(biāo)簽效果,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2018-05-05
  • Android實(shí)現(xiàn)記住賬號(hào)密碼功能

    Android實(shí)現(xiàn)記住賬號(hào)密碼功能

    這篇文章主要為大家詳細(xì)介紹了Android實(shí)現(xiàn)記住賬號(hào)密碼功能,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2020-10-10
  • Kotlin線程的橋接與切換使用介紹

    Kotlin線程的橋接與切換使用介紹

    這篇文章主要介紹了Android開發(fā)中Kotlin線程的橋接與切換,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2022-08-08
  • Android?TextView的maxEms和maxLength屬性區(qū)別

    Android?TextView的maxEms和maxLength屬性區(qū)別

    這篇文章主要為大家介紹了Android?TextView的maxEms和maxLength屬性區(qū)別,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2023-03-03
  • flutter圖片組件核心類源碼解析

    flutter圖片組件核心類源碼解析

    這篇文章主要為大家介紹了flutter圖片組件源碼解析,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2023-04-04
  • android @override 報(bào)錯(cuò)解決方案

    android @override 報(bào)錯(cuò)解決方案

    android @override 報(bào)錯(cuò):就是說Java 1.5的編譯器默認(rèn)對(duì)父類的方法進(jìn)行覆蓋,采用@Override進(jìn)行說明;但1.6已經(jīng)擴(kuò)展到對(duì)接口的方法;所以如果還是以Java 1.5的編譯器來編譯的話,會(huì)出現(xiàn)錯(cuò)誤
    2012-12-12
  • Android RecyclerView的簡(jiǎn)單使用

    Android RecyclerView的簡(jiǎn)單使用

    這篇文章主要為大家詳細(xì)介紹了Android RecyclerView簡(jiǎn)單使用的相關(guān)資料,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2017-03-03

最新評(píng)論

改则县| 台东市| 屏南县| 哈密市| 齐齐哈尔市| 如皋市| 泾阳县| 重庆市| 类乌齐县| 镇雄县| 沙雅县| 台中县| 常山县| 普陀区| 沙湾县| 越西县| 广饶县| 黎川县| 盱眙县| 平定县| 安新县| 广汉市| 宝丰县| 黄大仙区| 南充市| 汾阳市| 苍溪县| 神池县| 汝城县| 宝清县| 屏东市| 镇江市| 增城市| 集安市| 古交市| 昭觉县| 漾濞| 泰顺县| 阳东县| 嫩江县| 恭城|