Mix of expandable and normal listViews in android
I am trying to create a list similar to that in the call log acti开发者_Python百科vity (in Froyo). Here repeated calls from the same person are grouped into a expandable list item while others are normal elements in the list. How to create such a list? Can it be done with the ExpandableListView
class?
It should be rather easy with ExpandableListView. Extend BaseExpandableListAdapter to take control over the way group elements and expanded lists elements are displayed and how events triggered on them should work. Having that, you can organize this view to display non-expendable group for single element and expandable list for multiple elements. With such an adapter you can feed ExpendableListView to make it work
Example of its implementation below. Note that not all methods that needs to be implemented are shown here, as not related to the problem. Element is some imaginary class, which instances can tell for themselves how they should be displayed.
public class MyExpandableListAdapter extends BaseExpandableListAdapter {
private final List<Element> elements;
public MultiSelectExpandableListAdapter(Context c, List<Element> elements) {
this.elements = elements;
}
public View getGroupView(final int group, final boolean expanded, final View convertView,
final ViewGroup parent) {
if (elements.get(group).shouldBeDisplayedAsAGroup()) {
// inflate and setup view that displays expandable view header
} else {
// inflate and setup view of element that should be displayed as single element
}
}
public View getChildView(final int group, final int child, final boolean lastChild, final View convertView,
final ViewGroup parent) {
// inflate and setup child view
}
}
精彩评论