zoukankan      html  css  js  c++  java
  • android viewholder

     

    ViewHolder不是Android的开发API,而是一种设计方法,就是设计个静态类,缓存一下,省得Listview更新的时候,还要重新操作。 
        public View getView(int pos, View convertView, ViewGroup parent){ 

                ViewHolder holder; 

                if (convertView == null) { 

                    convertView = mInflater.inflate(R.layout.list_item, null); 

                    holder.text = (TextView) convertView.findViewById( R.id.text)); 

                    holder.icon = (ImageView) convertView.findViewButId( R.id.icon)); 

                    convertView.setTag(holder); 

                    } 

                else { 
                    holder = (ViewHolder) convertView.getTag(); 
                    } 

                holder.text.setText(DATA[pos]); 

                holder.icon.setImageBitmap((pos & 1) == 1 ? mIcon1 : mIcon2); 
                    return convertView; 
    //                holder = new ViewHolder(); 

                    } 



    //     ViewHolder 模式, 效率提高 50% 

            static class ViewHolder { 

                TextView text; 

                ImageView icon; 

                }
     
  • 相关阅读:
    sql 数据库还原脚本 (kill链接+独占
    最长回文字符串
    UVa 455 Periodic Strings
    UVa 1225 Digit Counting
    UVa 340 Master-Mind Hints
    UVa 10976
    UVa 725
    UVa 11059
    POJ1887 最长下降子序列
    最大连续子序列算法(数组的连续子数组最大和(首尾不相连))
  • 原文地址:https://www.cnblogs.com/wangyuehome/p/2972877.html
Copyright © 2011-2022 走看看