Android--ExpandbleView源码学习----ExpandableListPosition类

Class OverView

ExpandbaleListPosition类可以指向group的位置或则child的位置。可通过obtainChildPosition(int,int)和obtainGroupPosition(int)获得实例

/***根据type返回groupPosition或则childPosition的格式为64位的数据**/long getPackedPosition() { if (type == CHILD) return ExpandableListView.getPackedPositionForChild(groupPos, childPos); else return ExpandableListView.getPackedPositionForGroup(groupPos); }//static ExpandableListPosition obtain(int type, int groupPos, int childPos, int flatListPos) { ExpandableListPosition elp = getRecycledOrCreate(); elp.type = type; elp.groupPos = groupPos; elp.childPos = childPos; elp.flatListPos = flatListPos; return elp; }
//初始化对象
private void resetState() { groupPos = 0; childPos = 0; flatListPos = 0; type = 0; }

 //返回一个ExpandableListPosition,如果池中有对象则返回池中对象并且移除该对象(将被初始化),如果没有则新new一个对象返回 private static ExpandableListPosition getRecycledOrCreate() { ExpandableListPosition elp; synchronized (sPool) { if (sPool.size() > 0) { elp = sPool.remove(0); } else { return new ExpandableListPosition(); } } elp.resetState(); return elp; }//增加一个ExpandableListPosition对象到池中 
public void recycle() {
        synchronized (sPool) {
            if (sPool.size() < MAX_POOL_SIZE) {
                sPool.add(this);
            }
        }
    }

 
//获得一个ExpandableListPosition对象
 static ExpandableListPosition obtain(int type, int groupPos, int childPos, int flatListPos) { ExpandableListPosition elp = getRecycledOrCreate(); elp.type = type; elp.groupPos = groupPos; elp.childPos = childPos; elp.flatListPos = flatListPos; return elp; } //获得一个group类型的ExpandableListPosition对象static ExpandableListPosition obtainGroupPosition(int groupPosition) { return obtain(GROUP, groupPosition, 0, 0); } 
//获得一个child类型的ExpandableListPosition对象   
 static ExpandableListPosition obtainChildPosition(int groupPosition, int childPosition) { return obtain(CHILD, groupPosition, childPosition, 0); }

//根据位置的封装数据得到位置的ExpandbaleListPostion static ExpandableListPosition obtainPosition(long packedPosition) { if (packedPosition == ExpandableListView.PACKED_POSITION_VALUE_NULL) { return null; } ExpandableListPosition elp = getRecycledOrCreate(); elp.groupPos = ExpandableListView.getPackedPositionGroup(packedPosition); if (ExpandableListView.getPackedPositionType(packedPosition) == ExpandableListView.PACKED_POSITION_TYPE_CHILD) { elp.type = CHILD; elp.childPos = ExpandableListView.getPackedPositionChild(packedPosition); } else { elp.type = GROUP; } return elp; }


 
 

 
 
 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值