ExpandableListViewのPackedPosition
よくわからなかったのでコードを書いてログを出して確認してみました。
PackedPosition
は内部的に管理されているポジションのようです。
PackedPosition
はタイプがあって、親用(グループ)と子供用があります(Nullというのもあるが)。
使う時のパターンとしては
- 見えているアイテムの位置を取得
- PackedPositionの取得
- 親用(グループ)の位置の取得
- 子供用の位置の取得
となると思います。
PackedPosition
のタイプが子供の時は、そのPackedPosition
から親用(グループ)の位置の取得と子供用の位置の取得の両方が取得できます。PackedPosition
のタイプが親用(グループ)の時は、そのPackedPosition
から親用(グループ)の位置の取得ができ、子供用の位置は-1となります。
スクロールした時にログを出すコード
@Override public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) { ExpandableListView exp = (ExpandableListView) view; long getExpandableListPosition = exp.getExpandableListPosition(firstVisibleItem); int getPackedPositionType = ExpandableListView.getPackedPositionType(getExpandableListPosition); int getPackedPositionGroup = ExpandableListView.getPackedPositionGroup(getExpandableListPosition); int getPackedPositionChild = ExpandableListView.getPackedPositionChild(getExpandableListPosition); Log.d("xxx", String.format( "1st=%d, packec=%d, type=%d group=%d, child=%d", firstVisibleItem, getExpandableListPosition, getPackedPositionType, getPackedPositionGroup, getPackedPositionChild )); }
親のログ
/com.example.test11 D/xxx: 1st=3, packec=12884901888, type=0 group=3, child=-1 /com.example.test11 D/xxx: 1st=3, packec=12884901888, type=0 group=3, child=-1 /com.example.test11 D/xxx: 1st=3, packec=12884901888, type=0 group=3, child=-1 /com.example.test11 D/xxx: 1st=4, packec=17179869184, type=0 group=4, child=-1
子供のログ
/com.example.test11 D/xxx: 1st=5, packec=-9223372019674906624, type=1 group=4, child=0 /com.example.test11 D/xxx: 1st=5, packec=-9223372019674906624, type=1 group=4, child=0 /com.example.test11 D/xxx: 1st=5, packec=-9223372019674906624, type=1 group=4, child=0 /com.example.test11 D/xxx: 1st=5, packec=-9223372019674906624, type=1 group=4, child=0 /com.example.test11 D/xxx: 1st=6, packec=-9223372019674906623, type=1 group=4, child=1 /com.example.test11 D/xxx: 1st=6, packec=-9223372019674906623, type=1 group=4, child=1 /com.example.test11 D/xxx: 1st=6, packec=-9223372019674906623, type=1 group=4, child=1