Android 在可展开列表视图中展开所有子级

Android 在可展开列表视图中展开所有子级,android,expandablelistview,Android,Expandablelistview,我想在填充可展开列表视图时展开所有子级。 当前我的代码如下所示: ExpandableListView listView = (ExpandableListView) findViewById(R.id.view); int count = viewAdapted.getGroupCount(); for (int position = 1; position <= count; position++) listView.expandGroup(position - 1); Ex

我想在填充可展开列表视图时展开所有子级。 当前我的代码如下所示:

ExpandableListView listView = (ExpandableListView) findViewById(R.id.view);
int count = viewAdapted.getGroupCount();
for (int position = 1; position <= count; position++)
    listView.expandGroup(position - 1);
ExpandableListView listView=(ExpandableListView)findViewById(R.id.view);
int count=viewAdapted.getGroupCount();

对于(int position=1;position,您可以在自定义适配器的getGroupView中展开它:

@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;
}

Gluck!

将此代码放在适配器上将使expandlist保持打开状态,并禁用其关闭功能

ExpandableListView mExpandableListView = (ExpandableListView) parent;
mExpandableListView.expandGroup(groupPosition);
这可能是一个小的解决办法,但它的工作方式应该是。它打开所有组(在开始时),并可以随时关闭

 for ( int i = 0; i < groupList.getCount(); i++ ) {
    groupList.expandGroup(i);
 } 
for(int i=0;i
注: 在可展开视图上设置适配器后,请输入此代码,否则可能会导致错误。
希望有帮助。

首先填充适配器,然后将此代码放入oncreate方法中

   int count = adapter.getGroupCount();
                for ( int i = 0; i < count; i++ ) 
                    listView.expandGroup(i);
int count=adapter.getGroupCount();
for(int i=0;i
扩展所有组

for(int i=0; i < myAdapter.getGroupCount(); i++)
    myExpandableListView.expandGroup(i);

我尝试了列出的回答,但我发现我可以使用该方法获得组数

使用此方法,我可以迭代并扩展我的
ExpandableListView

for (int i = 0; i < myExpandableListView.getExpandableListAdapter().getGroupCount(); i++) {
      //Expand group
      myExpandableListView.expandGroup(i);
 }
for(int i=0;i
也许你可以这样看:显然这是目前唯一的解决方案。希望有一些属性或类似属性。当然(position@Drejc:你能选择正确的答案吗?有……但被删除了这让他们unclickable@DavidLawson:是的,我的解决方案是固定的扩展它们。如果你想扩展它们并且它们是可点击的,你必须在创建ExpandableListView的地方处理它们,就像Drejc的解决方案一样。
for (int i = 0; i < myExpandableListView.getExpandableListAdapter().getGroupCount(); i++) {
      //Expand group
      myExpandableListView.expandGroup(i);
 }