关于PinnedHeaderExpandableListView使用的时候on a null object reference

天天在各种博客论坛学习大神们的代码,所以觉得也应该把自己的东西拿出来分享和提问,如果有用不用谢我,如果无用也不要骂我,谢谢各位


问题:今天要写一个分组的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);

}




  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值