导航抽屉的ExpandableList仅填充数组的最后一项

时间:2015-06-30 15:34:14

标签: android expandablelistadapter

当我尝试在单个标题下填充导航抽屉项目(childItem)时,我只得到数组的最后一项,并获得与项目的数组大小相同的数量(数组的最后一项)

如果我有2个标题并尝试填充其childItems,则每个标题只能从其自己的arraylist中获取2个项目。

这是我看来的适配器类。

public class ExpandableListAdapter扩展了BaseExpandableListAdapter {

private Context context;
private List<String> listDataHeader; // header titles
private  HashMap<String, List<NavigationViewHolder>> listDataChild;

public ExpandableListAdapter(Context context, List<String> listDataHeader,  HashMap<String, List<NavigationViewHolder>> listChildData) {
    this.context = context;
    this.listDataHeader = listDataHeader;
    this.listDataChild = listChildData;
}


@Override
public Object getChild(int groupPosition, int childPosititon) {
    return listDataChild.get(this.listDataHeader.get(groupPosition)).get(childPosititon);
}

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

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

    final NavigationViewHolder childObj = (NavigationViewHolder) getChild(groupPosition, childPosition);

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

    TextView txtListChild = (TextView) convertView.findViewById(R.id.navig_body_section_item_title);
    ImageView imgChildView = (ImageView) convertView.findViewById(R.id.navig_body_section_item_icon);
  //  imgChildView.setImageResource(childObj.getImageId());
    txtListChild.setText(childObj.getTitleId());



    return convertView;
}

@Override
public int getChildrenCount(int groupPosition) {
    return 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 View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) {

    String headerTitle = (String) getGroup(groupPosition);
    if (convertView == null) {
        LayoutInflater infalInflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        convertView = infalInflater.inflate(R.layout.adapter_navigation_section_header, null);
    }

    TextView lblListHeader = (TextView) convertView.findViewById(R.id.navi_body_section_header_title);
    lblListHeader.setTypeface(null, Typeface.BOLD);
    lblListHeader.setText(headerTitle);

    return convertView;
}

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

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

}

0 个答案:

没有答案