本文介绍了ExpandabeListView自动崩溃的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我不能够关闭previously扩展群拓展新的组。我看过类似的问题,但我无法从中提取概念。我试着用collapseGroup(groupPosition)方法,但它不能正常工作。
I am not able to close a previously expanded group on expanding a new group. I have read similar questions, but I'm unable to extract concept from them. I tried using the collapseGroup (groupPosition) method, but it is not working.
推荐答案
您好,请尝试以下code。
Hi Please try below code.
int lastExpandedGroupPosition = 0;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
final ExpandableListView listView = (ExpandableListView) findViewById(R.id.listView);
listView.setOnGroupExpandListener(new OnGroupExpandListener() {
@Override
public void onGroupExpand(int groupPosition) {
// TODO Auto-generated method stub
if (groupPosition != lastExpandedGroupPosition) {
listView.collapseGroup(lastExpandedGroupPosition);
}
lastExpandedGroupPosition = groupPosition;
}
});
adapter = new ExpandableListAdapter(this, new ArrayList<String>(),
new ArrayList<ArrayList<Vehicle>>());
// Set this blank adapter to the list view
listView.setAdapter(adapter);
}
进口低于行。
import below line.
import android.widget.ExpandableListView.OnGroupExpandListener;
这篇关于ExpandabeListView自动崩溃的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!