ExpandableListView,如何将 child 范围最小值限制为 1 [如果没有项目则为 0]
ExpandableListView, how to limit the child range minimum to 1 [0 in case of no item]
我想在 ExpandableListView 的折叠状态下显示一个 child(在没有项目的情况下为 0)。 Android 给出 collapseGroup
但它折叠了所有项目。除了一个元素外,我想折叠 child。
任何线索或帮助将不胜感激。
如果 ExpandableListView 子组在 collapseGroup
上折叠时显示一个项目(如果为空则为 null)而不是 none 必须实现他的自己的 ExpandableListView 与自定义 ExpandableListConnector 实现相关,使用 "overriden" collapseGroup
和 expandGroup
方法。例如 collapseGroup
必须是:
boolean collapseGroup(int groupPos) {
ExpandableListPosition elGroupPos = ExpandableListPosition.obtain(
ExpandableListPosition.GROUP, groupPos, -1, -1);
PositionMetadata pm = getFlattenedPos(elGroupPos);
elGroupPos.recycle();
// Group will be collapsed until there will be presented 1 or null items
if (pm == null && mExpGroupMetadataList.size() <= 1) return false;
boolean retValue = collapseGroup(pm);
pm.recycle();
return retValue;
}
boolean collapseGroup(PositionMetadata posMetadata) {
/*
* Collapsing requires removal from mExpGroupMetadataList
*/
/*
* If it is null, it must be already collapsed. This group metadata
* object should have been set from the search that returned the
* position metadata object.
*/
// Group will be collapsed until there will be presented 1 or null items
if (posMetadata.groupMetadata == null && mExpGroupMetadataList.size() <= 1) return false;
// Remove the group from the list of expanded groups
mExpGroupMetadataList.remove(posMetadata.groupMetadata);
// Refresh the metadata
refreshExpGroupMetadataList(false, false);
// Notify of change
notifyDataSetChanged();
// Give the callback
mExpandableListAdapter.onGroupCollapsed(posMetadata.groupMetadata.gPos);
return true;
}
必须为 expandGroup
实施类似的逻辑。
我想在 ExpandableListView 的折叠状态下显示一个 child(在没有项目的情况下为 0)。 Android 给出 collapseGroup
但它折叠了所有项目。除了一个元素外,我想折叠 child。
任何线索或帮助将不胜感激。
如果 ExpandableListView 子组在 collapseGroup
上折叠时显示一个项目(如果为空则为 null)而不是 none 必须实现他的自己的 ExpandableListView 与自定义 ExpandableListConnector 实现相关,使用 "overriden" collapseGroup
和 expandGroup
方法。例如 collapseGroup
必须是:
boolean collapseGroup(int groupPos) {
ExpandableListPosition elGroupPos = ExpandableListPosition.obtain(
ExpandableListPosition.GROUP, groupPos, -1, -1);
PositionMetadata pm = getFlattenedPos(elGroupPos);
elGroupPos.recycle();
// Group will be collapsed until there will be presented 1 or null items
if (pm == null && mExpGroupMetadataList.size() <= 1) return false;
boolean retValue = collapseGroup(pm);
pm.recycle();
return retValue;
}
boolean collapseGroup(PositionMetadata posMetadata) {
/*
* Collapsing requires removal from mExpGroupMetadataList
*/
/*
* If it is null, it must be already collapsed. This group metadata
* object should have been set from the search that returned the
* position metadata object.
*/
// Group will be collapsed until there will be presented 1 or null items
if (posMetadata.groupMetadata == null && mExpGroupMetadataList.size() <= 1) return false;
// Remove the group from the list of expanded groups
mExpGroupMetadataList.remove(posMetadata.groupMetadata);
// Refresh the metadata
refreshExpGroupMetadataList(false, false);
// Notify of change
notifyDataSetChanged();
// Give the callback
mExpandableListAdapter.onGroupCollapsed(posMetadata.groupMetadata.gPos);
return true;
}
必须为 expandGroup
实施类似的逻辑。