在 ExpandableListView 中加载 activity 时展开所有视图

expand all view when activity is load in ExpandableListView

我的问题是...
我在 activity 中使用可扩展列表视图。 当 activity 创建时,它显示所有 child 组都已折叠。 我想在填充可扩展列表视图时展开所有 children。
喜欢

为此,我在 getGroupView() 方法适配器 class

中使用了以下代码
ExpandableListView eLV = (ExpandableListView) parent         
eLV.expandGroup(groupPosition,true);

现在群组已展开,但它不能让我通过单击群组 header 来折叠。

您可以在自定义 getGroupView() 中扩展它 Adapter:

@Override
public View getGroupView(int groupPosition, boolean isExpanded, View convertView,
                         ViewGroup parent) {
    View v = super.getGroupView(groupPosition, isExpanded, convertView, parent);
    ExpandableListView mExpandableListView = (ExpandableListView) parent;
    mExpandableListView.expandGroup(groupPosition);
    return v;
}

只需添加 groupClickListenerreturn true 即可禁用折叠子列表。将此代码添加到您的 activity.

yourExpandableList.setOnGroupClickListener(new OnGroupClickListener() {
  @Override
  public boolean onGroupClick(ExpandableListView parent, View v,
                              int groupPosition, long id) { 
    return true; // This way the expander cannot be collapsed
  }
});