【问题标题】:expand all view when activity is load in ExpandableListView在 ExpandableListView 中加载活动时展开所有视图
【发布时间】:2019-02-25 23:04:21
【问题描述】:
我的问题是……
我在我的活动中使用可扩展列表视图。
创建活动时,它显示所有子组已折叠。
我想在填充可展开列表视图时展开所有子项。
喜欢
为此,我在getGroupView()方法适配器类中使用了以下代码
ExpandableListView eLV = (ExpandableListView) parent
eLV.expandGroup(groupPosition,true);
现在组已展开,但无法通过单击组标题来折叠。
【问题讨论】:
标签:
android
expandablelistview
【解决方案1】:
只需添加groupClickListener 和return true 即可禁用折叠子列表。将此代码添加到您的活动中。
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
}
});
【解决方案2】:
您可以在自定义Adapter 中将其扩展为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;
}