可扩展的列表视图
我正在使用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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
当您单击一项时,您可以循环浏览其余项目并折叠除您刚刚单击的一项之外的每一项...
When you click one item you could loop through the rest and collapse each one except for the one you just clicked...
您可以按照基兰的建议进行操作,或者如果您一次只打开一个,您可以只跟踪您最后单击的是哪一个。您可以通过在类主体中声明
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, putlist.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.
首先在您的 Activity 中实现 OnGroupExpandListener ,这将允许您添加其默认方法,添加默认方法后,您需要这样做:
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: