android 在ExpandableListView 添加不同的子项视图

 在 getChildTypeCount 定义为实际类型数

@Override
public int getChildTypeCount() {
// TODO Auto-generated method stub
return 3;
}

@Override
public int getChildType(int groupPosition, int childPosition) {
// TODO Auto-generated method stub
try {
int size=getChildrenCount(groupPosition);
if (childPosition == 0) {
return IMsgViewType.TYPE_TOP;
} else if (childPosition==size - 1) {
return IMsgViewType.TYPE_BOTTOM;
} else {
return IMsgViewType.TYPE_MIDDLE;
}
} catch (Exception e) {
// TODO: handle exception
System.out.println("Exception-->>" + e.toString());
return IMsgViewType.TYPE_BOTTOM;
}
}

判断时 总是报

如果改getChildTypeCount()  为

ArrayIndexOutOfBoundsException: length=4; index=4

@Override
public int getChildTypeCount() {
// TODO Auto-generated method stub
return 4;
}

就行了

你可能感兴趣的:(android 在ExpandableListView 添加不同的子项视图)