2

我在我的项目中实现了 n 级消耗品列表,但我无法找到内部消耗品列表的实际大小。例如,第一级消耗品列表有 4 个孩子,当我点击第一级项目时,它显示正确,他们又有 4 个孩子,但我只能看到 2 或 3 个孩子。我与您分享我的代码,请帮助我。

这是我的 ExpandableListAdapter 类:

public class ExpandableListAdapter extends BaseExpandableListAdapter {
Context context;
LinkedHashMap objhashTable;

public ExpandableListAdapter(Context con, LinkedHashMap objhashTable) {
    // TODO Auto-generated constructor stub
    this.context = con;
    this.objhashTable = objhashTable;
    Log.i("ParentView", "objhashTable  == " + objhashTable.size());
    // nu

}

@Override
public Object getChild(int arg0, int arg1) {
    return arg1;
}

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

@Override
public View getChildView(int groupPosition, int childPosition,
        boolean isLastChild, View convertView, ViewGroup parent) {
    //Log.i("ParentView", "getChildView  == " + childPosition
        //  + "  groupPosition  == " + groupPosition+"   parent  == "+conve);
    //parent.
    LinkedHashMap temp = getSelectedObject(groupPosition);
    if (temp != null && getSelectedObject(groupPosition) != null ) {
        ExpandableListAdapter parebnt = new ExpandableListAdapter(context, temp);
        LayoutInflater inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        convertView = inflater.inflate(R.layout.expendablelist, parent, false);
        ExpandableListView NextLevelAdapter =(ExpandableListView)convertView.findViewById(R.id.ParentLevel123);
        TextView txt = (TextView)convertView.findViewById(R.id.txtLevel);
        txt.setText(getSelectedKey(groupPosition) );
        txt.setTextColor(Color.BLACK);
        txt.setTag(getSelectedKey(groupPosition));
        txt.setTextSize(20);
        txt.setBackgroundColor(Color.BLUE);
        txt.setPadding(10, 7, 7, 7);
        //CustExpListview SecondLevelexplv = new CustExpListview(context);
        NextLevelAdapter
                .setAdapter(/* new SecondLevelAdapter(context) */parebnt);
        NextLevelAdapter.setGroupIndicator(null);
        convertView.measure( MeasureSpec.AT_MOST, MeasureSpec.AT_MOST );
         convertView.getLayoutParams().height = convertView.getMeasuredHeight();
        return convertView;
    }else{
        return null;

    }
}



@Override
public Object getGroup(int groupPosition) {
    return groupPosition;
}

@Override
public int getGroupCount() {
    //if (objhashTable != null ) 
    //Log.i("ParentLevel", "objhashTable == "+objhashTable);
           return objhashTable.size();

}

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



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

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

private LinkedHashMap getSelectedObject(int groupPos) {
    LinkedHashMap lnmap = null;
    if (objhashTable != null) {
        Iterator it = objhashTable.keySet().iterator();
        int i = 0;
        while (it.hasNext()) {
            String type = (String) it.next();
            if (i == groupPos) {
                lnmap = (LinkedHashMap) objhashTable.get(type);
                // childCount =lnmap.size();
                break;
            }
            i++;
        }

    }
    return lnmap;
}

private String getSelectedKey(int groupPos) {
    String type = null;
    if (objhashTable != null) {
        Iterator it = objhashTable.keySet().iterator();
        int i = 0;
        while (it.hasNext()) {
            type = (String) it.next();
            if (i == groupPos) {
                // lnmap = (LinkedHashMap)objhashTable.get(type);
                // childCount =lnmap.size();
                break;
            }
            i++;
        }

    }
    return type;
}

@Override
public int getChildrenCount(int groupPosition) {
    // TODO Auto-generated method stub
    return 1;
}

@Override
public View getGroupView(int groupPosition, boolean isExpanded,
        View convertView, ViewGroup parent) {
    // TODO Auto-generated method stub
    return null;
}
}
4

0 回答 0