天天在各种博客论坛学习大神们的代码,所以觉得也应该把自己的东西拿出来分享和提问,如果有用不用谢我,如果无用也不要骂我,谢谢各位
问题:今天要写一个分组的ListView带分组悬停效果的,看到这篇博文http://blog.csdn.net/h7870181/article/details/40400155,就直接用了。但是博主数据源用的是二维数组存放的,所以自己用List<List<Object>>的方式存放,结果使用的时候直接崩溃了,跟着log找到问题的地方
@Override
protected void onLayout(boolean changed, int left, int top, int right,
int bottom) {
super.onLayout(changed, left, top, right, bottom);
final long flatPostion = getExpandableListPosition(getFirstVisiblePosition());
final int groupPos = ExpandableListView
.getPackedPositionGroup(flatPostion);
final int childPos = ExpandableListView
.getPackedPositionChild(flatPostion);
int state = mAdapter.getHeaderState(groupPos, childPos); 这里报错 on a null object reference 大概是说引用了空的对象吧
if (mHeaderView != null && null != mAdapter && state != mOldState) {
mOldState = state;
mHeaderView.layout(0, 0, mHeaderViewWidth, mHeaderViewHeight);
}
configureHeaderView(groupPos, childPos);
}
找不到问题出在哪里,不过后来把这里改成这样就可以,但是为什么会空值就不清楚了,知道的请留言说说,谢谢
@Override
protected void onLayout(boolean changed, int left, int top, int right,
int bottom) {
super.onLayout(changed, left, top, right, bottom);
final long flatPostion = getExpandableListPosition(getFirstVisiblePosition());
final int groupPos = ExpandableListView
.getPackedPositionGroup(flatPostion);
final int childPos = ExpandableListView
.getPackedPositionChild(flatPostion);
if (null != mAdapter) {
int state = mAdapter.getHeaderState(groupPos, childPos);
if (mHeaderView != null && state != mOldState) {
mOldState = state;
mHeaderView.layout(0, 0, mHeaderViewWidth, mHeaderViewHeight);
}
}
configureHeaderView(groupPos, childPos);
}