2017-03-06 3 views
1

Dies ist mein expandlable Liste Adapter AnrufWie implementiert man mehrstufige erweiterbare Listenansicht mit einem einzigen Adapter?

TableOfContentsAdapter adapter = new TableOfContentsAdapter(TableOfContentsActivity.this,toCList); 
mExpandableListViewTOC.setAdapter(adapter); 

Und das ist meine Adapter Implementierung

class TableOfContentsAdapter extends BaseExpandableListAdapter { 

private Context context; 
private List<TOCLink> tocLinks; 

public TableOfContentsAdapter(Context context, List<TOCLink> tocLinks) { 
    this.context = context; 
    this.tocLinks = tocLinks; 
} 

@Override 
public int getChildrenCount(int groupPosition) { 
    return tocLinks.get(groupPosition).getTocLinks().size(); 
} 

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

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

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

@Override 
public Object getChild(int groupPosition, int childPosition) { 
    List<TOCLink> childTocLinks = tocLinks.get(groupPosition).getTocLinks(); 
    return childTocLinks.get(childPosition); 
} 

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

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

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

@Override 
public View getGroupView(int groupPosition, boolean b, View convertView, ViewGroup viewGroup) { 
    TOCLink tocLink = (TOCLink) getGroup(groupPosition); 
    if (convertView == null) { 
     LayoutInflater inflater = (LayoutInflater) this.context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
     convertView = inflater.inflate(R.layout.list_header, null); 
    } 

    TextView groupHeader = (TextView) convertView.findViewById(R.id.header); 
    groupHeader.setText(tocLink.getSectionTitle()); 

    return convertView; 
} 

@Override 
public View getChildView(int groupPosition, int childPosition, boolean b, View convertView, ViewGroup viewGroup) { 
    TOCLink tocLink = (TOCLink) getChild(groupPosition, childPosition); 
    if (convertView == null) { 
     LayoutInflater inflater = (LayoutInflater) this.context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
     convertView = inflater.inflate(R.layout.list_item, null); 
    } 

    TextView childItem = (TextView) convertView.findViewById(R.id.item); 
    childItem.setText(tocLink.getSectionTitle()); 

    /*TOCLink tocLink1 = tocLinks.get(groupPosition).getTocLinks().get(childPosition); 
    if (tocLink1.getTocLinks().size() > 0) { 
     new TableOfContentsAdapter(context, tocLink1.getTocLinks()); 
    }*/ 
    return convertView; 
} 

}

I Multi-Level-erweiterbar Listenansicht mit einzelnen Adapter implementieren möchten. Problem hier ist, ich bin in der Lage zu Level 1 zu gehen, aber nicht weiter.

Wie kann dieses Problem gelöst werden?

Antwort

Verwandte Themen