扩展名列表中的android:getChildView每个项目被调用9次

时间:2015-09-25 11:28:04

标签: android view expandablelistview

我使用expandableListView开发应用程序,使用自定义适配器。问题是每个项目多次调用getChildView。例如,对于有一个孩子的组,该方法被调用9次。

我不确定附加什么代码,我会附上getChildView(),如果你需要另外一个,请在评论中写一下

@Override
    public View getChildView(int groupPosition, int childPosition, boolean b, View convertView, ViewGroup viewGroup) {
        Vehicle vehicle = (Vehicle) getChild(groupPosition, childPosition);
        if (convertView == null) {
            LayoutInflater infalInflater = (LayoutInflater) fragment.getActivity()
                    .getSystemService(fragment.getActivity().LAYOUT_INFLATER_SERVICE);
            convertView = infalInflater.inflate(R.layout.child_item, null);
        }
        TextView tv = (TextView) convertView.findViewById(R.id.country_name);
        ImageView iv = (ImageView) convertView.findViewById(R.id.flag);

        tv.setText(vehicle.getUname().toString());
        //TODO load image
        return convertView;
    }

任何帮助都会受到重视

1 个答案:

答案 0 :(得分:0)

getChilderCount(int groupPosition)是否正确覆盖?

根据您要存储的数据类型,可能应该是return getGroup(groupPosition).size()的内容。