单击子项时关闭可扩展ListView
问题描述:
我实现了以下可扩展列表视图的方法.现在,单击父级时,listView折叠.我想做的是将列表设置为在按下孩子时折叠(不仅是组).尽管正在搜索,但是我不明白我需要重写/实现哪种方法.谢谢!
I have the following methods of the expandable list view implemented. Now, when the parent is clicked, the listView is collapsed. What I want to do, is set the list to collapse when the child is pressed (not only the group). Though I was searching, I can't understand which method I need to override/implement. Thanks!
expListView.setOnGroupClickListener(new ExpandableListView.OnGroupClickListener() {
@Override
public boolean onGroupClick(ExpandableListView parent, View v,
int groupPosition, long id) {
parent.collapseGroup(groupPosition);
return false;
}
});
expListView.setOnGroupExpandListener(new ExpandableListView.OnGroupExpandListener() {
@Override
public void onGroupExpand(int groupPosition) {
}
});
expListView.setOnGroupCollapseListener(new ExpandableListView.OnGroupCollapseListener() {
@Override
public void onGroupCollapse(int groupPosition) {
}
});
expListView.setOnChildClickListener(new ExpandableListView.OnChildClickListener() {
@Override
public boolean onChildClick(ExpandableListView parent, View v,
int groupPosition, int childPosition, long id) {
return false;
}
});
答
您需要做的就是添加以下代码行:
All you need to do is add this line of code:
@Override
public boolean onGroupClick(ExpandableListView parent, View v,
int groupPosition, long id) {
parent.collapseGroup(groupPosition);
return false;
}