2 ccx1070064553 ccx1070064553 于 2017.09.07 18:13 提问

android开发中的ExpandableListView的adapter里的getview是干啥的
public View getChildView(int groupPosition, int childPosition,
boolean isLastChild, View convertView, ViewGroup parent) {
    ViewHolder holder = null;
    if (convertView == null) {
        convertView = mInflater.inflate(R.layout.main_menu_list_child, null);
        holder = new ViewHolder();
        holder.mChildIcon = (ImageView) convertView.findViewById(R.id.desktop_list_child_icon);
        holder.mChildName = (TextView) convertView.findViewById(R.id.desktop_list_child_name);
        convertView.setTag(holder);
    } else {
        holder = (ViewHolder) convertView.getTag();
    }
    AbMenuItem m = mChilds.get(groupPosition).get(childPosition);
    holder.mChildIcon.setImageResource(m.getIconId());
    holder.mChildName.setText(m.getText());
    return convertView;
}

convertView和holder是什么?

1个回答

han_li_chao00
han_li_chao00   2017.12.22 10:29

列表在绘制时会调用getView(), 拿到item的view也就是contentview, holder相当于保存item的子view的容器, 可以复用view

Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!