Android ViewHolder 案例

來源:互聯網
上載者:User

標籤:android   ar   os   sp   on   bs   amp   as   tt   

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; 

            } 

Android ViewHolder 案例

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.