编程折叠组ExpandableListView [英] Programmatically collapse a group in ExpandableListView

查看:198
本文介绍了编程折叠组ExpandableListView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我展开一个新的组,可我崩溃的最后一个扩展的?

When I expand a new group, can I collapse the last one expanded?

推荐答案

尝试把这个在你的 ExpandableListAdapter 的ListView 是引用 ExpandableListView 本身。而 lastExpandedGroupPosition 里面定义了一个整数成员变量的 ExpandableListAdapter

Try putting this in your ExpandableListAdapter, listView is a reference to the ExpandableListView itself. And lastExpandedGroupPosition is a integer member variable defined inside your ExpandableListAdapter.

    @Override
    public void onGroupExpanded(int groupPosition){
        //collapse the old expanded group, if not the same
        //as new group to expand
        if(groupPosition != lastExpandedGroupPosition){
            listView.collapseGroup(lastExpandedGroupPosition);
        }

        super.onGroupExpanded(groupPosition);           
        lastExpandedGroupPosition = groupPosition;
    }

这篇关于编程折叠组ExpandableListView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆