ExpandableList视图在组中零项的情况下崩溃

时间:2013-08-23 11:53:55

标签: android android-listview expandablelistview expandablelistadapter

1:如果任何一组没有物品,那么它就会崩溃

2:如果只有一个组,那么在打开该组后它只显示一个项目。

       public class AssignmentCompletedExpandableAdapter extends BaseExpandableListAdapter {

            private List<String> _listDataHeader; 

            private HashMap<String, List<AssignmentScore>> _listDataChild;

            public AssignmentCompletedExpandableAdapter( List<String> _listDataHeader, 
                                                         HashMap<String, List<AssignmentScore>> _listDataChild ){
                 this._listDataHeader = _listDataHeader;
                 this._listDataChild  = _listDataChild;
            }

            @Override
            public Object getChild(int groupPosition, int childPosititon) {

                        return _listDataChild.get(_listDataHeader.get(groupPosition)).get(childPosititon);

            }

            @Override
            public long getChildId(int groupPosition, int childPosition) {
                return childPosition;
            }

            @Override
            public int getChildrenCount(int groupPosition) {
                return this._listDataChild.size();
            }

            @Override
            public Object getGroup(int groupPosition) {
                return this._listDataHeader.get(groupPosition);
            }

            @Override
            public int getGroupCount() {
                return this._listDataHeader.size();
            }

            @Override
            public long getGroupId(int groupPosition) {
                return groupPosition;
            }

            @Override
            public boolean hasStableIds() {
                return false;
            }

            @Override
            public boolean isChildSelectable(int groupPosition, int childPosition) {
                return false;
            }

            @Override
            public View getChildView( int groupPosition, int childPosition, boolean isLastChild,
                                      View convertView, ViewGroup parent) {

                    if( convertView == null ){
                            convertView = ((LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE)).
                                                          inflate(R.layout.layout, null); 

                    }



                            Data data = (Data ) getChild(groupPosition, childPosition);
                        TaggedView view = TaggedView.getTaggedView(convertView);

                            view .name_textView.setText(data.getName());
                            view .score_textView.setText(data.getScore());


                    return convertView;

            }

            @Override
            public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) {

                 if( convertView == null ){
                        convertView =  ((LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE)).
                                                        inflate(R.layout.layoutgroup, null); 
                  }

                 TextView lblListHeader = (TextView)convertView.findViewById(R.id.groupname);
                 lblListHeader.setText((String)getGroup(groupPosition));

                 return convertView;

            }

        }

1 个答案:

答案 0 :(得分:0)

我认为你的getChildrenCount应该按照以下方式更改,以便按预期工作。如果有效,请告诉我。

    @Override
    public int getChildrenCount(int groupPosition) {
        return this._listDataChild.get(_listDataHeader.get(groupPosition)).size();
    }