问题描述
我是Android开发的新手.我遵循了本教程来显示ExpandableListView
及其正常工作.如果我按所有组,则所有组都会展开.
I am new to Android development. I followed this tutorial for showing ExpandableListView
and its working properly. If I press all group then all group will expand.
我一次只能扩展一组.开始时,第一个组将自动展开,如果我点击另一个组,则第一个组将折叠,而最近的组将展开.有可能吗?
I want to expand only one group at a time. At the beginning, the first group will expand automatically and If I tap another group then the first group will collapse and the recent group will expand. Is it possible?
如果可以的话我该怎么办.有什么建议吗?
If possible then how can I get. Any suggestion?
推荐答案
您可以使用GroupExpandListener
来实现.将最后一个扩展位置存储到变量中,然后使用此变量将collapseGroup存储起来
You may achieve using GroupExpandListener
.Store last Expanded position to variable and collapseGroup using this variable
private int lastPosition = -1;
private ExpandableListView lv; //your expandable listview
lv.setOnGroupExpandListener(new OnGroupExpandListener() {
@Override
public void onGroupExpand(int groupPosition) {
if (lastPosition != -1
&& groupPosition != lastPosition) {
lv.collapseGroup(lastPosition);
}
lastPosition = groupPosition;
}
});
这篇关于只有一组会在ExpandableListView中展开的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!