只有一组会在ExpandableListView中展开 [英] Only one group will expand in ExpandableListView

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

问题描述

我是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存储起来<​​/p>

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中展开的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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