【问题标题】:How to know whether particular group is exist in ExapndableListView?如何知道 ExapndableListView 中是否存在特定组?
【发布时间】:2019-11-21 21:29:22
【问题描述】:

因为我想这样做:

expandableListView.expandGroup(4);

因为有时它不存在,因为我根据用户删除删除了标题

或者告诉我另一种方法给 pos 不硬编码 expandableListView.expandGroup(4);

编辑:

if (expandableCategoryAdapter.getGroupCount() == 5) {
                            expandableListView.expandGroup(4);
                        }

我想做的不是 4 和 5,而是取决于适配器/列表的大小。 我怎样才能做到这一点?我不想硬核 4 和 5

【问题讨论】:

  • ExpandableListAdapter 的 getGroupView() 中有一个参数,一个布尔值,表示组是否展开。 stackoverflow.com/questions/28907941/…
  • getGroupCount 将返回组数 .. 另外,您不要使用一些随机整数调用 expandGroup 它应该小于组数。
  • @ADM 原因:我想扩展特定组而不是全部
  • @JaiminModi 请查看更新后的问题
  • @ADM 请查看更新后的问题

标签: android android-listview


【解决方案1】:

尝试使用此代码 → 首先您必须检查 expandableListView 有多少组。

int groupCount = expandableListView.getExpandableListAdapter().getGroupCount();
        if (x < groupCount) {
            expandableListView.expandGroup(x);
        } else {
            (your own code) }

【讨论】:

    猜你喜欢
    • 2019-07-22
    • 2018-09-13
    • 1970-01-01
    • 1970-01-01
    • 2018-10-23
    • 1970-01-01
    • 2018-01-06
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多