ListView中getView()和ViewHolder次数

  • getView()在ListView中会不断的被调用,无论是用convertView + ViewHolder进行优化。
  • ViewHolder只会被创建一个屏幕中条目的个数,即convertView == null条件满足的次数
class TigerAdapter extends BaseAdapter {

        @Override
        public int getCount() {
            // TODO Auto-generated method stub
            return 500;
        }

        @Override
        public Object getItem(int position) {
            // TODO Auto-generated method stub
            return null;
        }

        @Override
        public long getItemId(int position) {
            // TODO Auto-generated method stub
            return 0;
        }

        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            System.out.println("我被调用了!!!!!" + position);
            ViewHolder viewHolder;
            if (convertView == null) {
                convertView = new TextView(mContext);
                
                viewHolder = new ViewHolder();
                System.out.println("ViewHolder被调用了");
                

                convertView.setTag(viewHolder);
            } else {
                viewHolder = (ViewHolder) convertView.getTag();
            }
            ((TextView) convertView).setTextSize(28);
            return convertView;
        }

    }
ListView中getView()和ViewHolder次数_第1张图片
Paste_Image.png

你可能感兴趣的:(ListView中getView()和ViewHolder次数)