可扩展的列表视图

发布于 2024-11-27 03:51:25 字数 118 浏览 6 评论 0原文

我正在使用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.

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

转身以后 2024-12-04 03:51:25

当您单击一项时,您可以循环浏览其余项目并折叠除您刚刚单击的一项之外的每一项...

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);
            }
        }
    }

});

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);
            }
        }
    }

});
调妓 2024-12-04 03:51:25

您可以按照基兰的建议进行操作,或者如果您一次只打开一个,您可以只跟踪您最后单击的是哪一个。您可以通过在类主体中声明 int lastclicked 来实现此目的,然后按照韩语建议在侦听器中声明 list.collapseGroup(lastclicked)

我会给出一个代码示例,但我在我的手机上。对不起。

但我个人更喜欢使用lastclicked 方法而不是使用for 循环。看起来更有效率。

You could do as kieran suggested, or if you only have one open at a time, you could just keep track of which one you last clicked. You could do this by declaring int lastclicked in the class body then in the listener as Korean suggested, put list.collapseGroup(lastclicked)

I would give a code example, but I'm on my mobile. Sorry.

But I just personally prefer the lastclicked method of doing it than using a for loop. It seems more efficient.

感情洁癖 2024-12-04 03:51:25

首先在您的 Activity 中实现 OnGroupExpandListener ,这将允许您添加其默认方法,添加默认方法后,您需要这样做:

@Override
    public void onGroupExpand(int groupPosition) {
        // TODO Auto-generated method stub
        int len = expadapter.getGroupCount();           
        for(int i=0;i<len;i++)
        {
            if(i!=groupPosition)
            {
                expandlst.collapseGroup(i);
            }
        }
    }

First of all implement OnGroupExpandListener in your Activity that will allow you to add its default method, and after add that default method you need to do like this:

@Override
    public void onGroupExpand(int groupPosition) {
        // TODO Auto-generated method stub
        int len = expadapter.getGroupCount();           
        for(int i=0;i<len;i++)
        {
            if(i!=groupPosition)
            {
                expandlst.collapseGroup(i);
            }
        }
    }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文