Android -- ExpandbleView 원본 학습 --- expandableListPosition 클래스

3227 단어 position
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;
}
< pre class = "java" name = "code" > / 대상 초기 화 < / pre >
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);
}
}
}
< pre class = "java" name = "code" > / ExpandableListPosition 대상 을 가 져 옵 니 다 < / pre >
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);
}
< pre class = "java" name = "code" > / / child 형식의 ExpandableListPosition 대상 획득
static ExpandableListPosition obtainChildPosition(int groupPosition, int childPosition) { return obtain(CHILD, groupPosition, childPosition, 0); }< pre class = "java" name = "code" > / 위치 에 따 른 패 키 징 데이터 로 위 치 를 얻 는 ExpandbaleListPostion static ExpandableListPosition obtainPosition (long packed Position) {if (packed Position = = 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; }

좋은 웹페이지 즐겨찾기