Usage of '_id' on ExpandableListView with a CursorTreeAdapter
-
21-12-2019 - |
質問
Usage of _id
is not clear enough in my mind. Considering all possible actions(onChildClick
,onItemClick
,onExpand
,onCollapse
etc. or even drawings) on ExpandableListView
below;
=A==============
-B-----------
-C-----------
=D==============
-E-----------
-B----------- //Note: B is included in both groups
is it OK to use same _id
values with CursorTreeAdapter
on following relations:
- B with C (this is problem I know)
- A with D (this is problem too, I know)
- A with B (this is what I am confused)
- E with C (also this one confuses me)
- E with B (possible problem)
- C with D (OK, I guess)
解決
The _id
simply has to be unique for any given category. In other words the parents (groups) must have a unique _id
from each other and each individual child within a particular group should have a unique _id
from each other but it doesn't matter if any have the same _id
as a parent.
Using your example, groups A & D should not have the same _id
.
In group A, children B & C should not have the same _id
as each other but if one of them has the same _id
as group A or group D then it doesn't matter.
In group D, children E & B should not have the same _id
and, again, if one of them has the same _id
as group A or group D this also doesn't matter.
Finally, child B in both groups can (and probably will) have the same _id
in both instances.
In short, the CursorTreeAdapter
requires a single Cursor
for the groups and multiple separate Cursors
for each set of children. None of these are directly related and each are self-contained.