可扩展的ListViewListView

2023-09-04 23:58:40 作者:碾压安醚的孤独

我使用expandableListView的UI设计,所以我想知道Android的可扩展列表视图,有没有办法只允许一个列表项展开,即当您单击并展开一个项目,其他项目自动崩溃了。

I am using expandableListView for UI design, so I am wondering for Android expandable listview, is there a way to allow only one list item expanded, i.e. when you click and expand an item, all other items are collapsed automatically.

感谢

推荐答案

当你点击一个项目,你可以通过剩下的循环和折叠每个人除了一个你只需点击...

When you click one item you could loop through the rest and collapse each one except for the one you just clicked...

list.setOnGroupExpandListener(new OnGroupExpandListener() {

    public void onGroupExpand(int groupPosition) {
        int len = mAdapter.getGroupCount();

        for(int i=0; i<len; i++) {
            if(i != groupPosition) {
                list.collapseGroup(i);
            }
        }
    }

});