android - 多层ExpandableListView

标签 android expandablelistview expandablelistadapter

我目前正在做一个项目,我需要以下内容:

- MainGroup 1 (Expandable)
  - SubGroup 1 (Expandable)
    - SubSubGroup 1 (Expandable)
      - Child View
      - Child View
      - ...
    - SubSubGroup 2 (Expandable)
      - Child View
      - Child View
      - ...
  - SubGroup 2 (Expandable)
    - SubSubGroup 3 (Expandable)
      - Child View
      - ...
    - SubSubGroup 4 (Expandable)
      - Child View
      - ...
  - SubGroup 3 (Expandable)
    - Child View
    - ...
- MainGroup 2 (Expandable)
  - ...

最多只能是 ExpandableListViewExpandableListView 内在 ExpandableListView 内- 所以3层ExpandableListView :

  • MainGroup只会持有其他ExpandableListView .
  • SubGroup将持有其他ExpandableListView除了最后两个,它们总是 ChildViews . (我认为这两个可以用 SubSubGroup 的一个代替)
  • SubSubGroup会一直持有ChildViews .

我的问题是我认为我无法理解 ExpandableListView 的基本原理。布局它的 child 。我看过像 this 这样的例子,但无法理解该功能。

我试过简单地添加一个 ExpandableListView作为另一个 child 的 child -但某些东西不能仅作为内部ExpandableListView的第一项工作如果您展开其中一个外部组,则可见。但是,我可以通过手动设置外部组容器的高度使其足够大以显示内部 ExpandableListView 中的所有项目.为了达到最佳效果,当然应该即时计算高度。

所以,要解决一些更具体的问题:

  • 谁能给我解释一下ExpandableListView “生命周期”(我的意思是实例化、 View 的重用、展开/折叠监听器)包括:
    • ExpandableListView 的方式和时间通知 child 展开/折叠?
    • ExpandableListView 怎么样?知道要为所有 child 腾出多少空间才能放入一个团体容器吗?
  • 使用ExpandableListView 有多少好处?与使用一些 LinearLayouts 将我自己的解决方案混合在一起相比,创建上述内容还有一些 OnClickListeners ?

编辑

对于我的最后一个问题,我可能会注意到可以有 1 到 20+ MainGroups .

最佳答案

首先,让我推荐你GrepCode地点。它有 Android SDK 类的来源。感谢他们,我已经找到了 AdapterViews 的基本原理(我给了你一个 ExpandableListView 的链接,但如果你不仅研究它,而且研究它的类父项会更好)。

现在,你的问题和我的答案:

How and when is an ExpandableListView notified that a child is expanded/collapsed?

见方法handleItemClick(View v, int position, long id)

How does the ExpandableListView know how much space to make for all children to fit into a group container?

这个问题我没有好好研究,但据我所知,它是由requestLayout()方法做出来的。我们还发现一个可 ScrollView 不能嵌入到另一个可 ScrollView 中。 (这是众所周知的错误:将 ListView 放入 ScrollView 或将 ListView 放入 ExpandableListView)。

How much benefit is there in using the ExpandableListView to create the above, compared to just mixing together my own solution using some LinearLayouts and some OnClickListeners?

AdapterView 更快。但是即使对于 ExpandableListView,您的构造也太复杂了。您可以使用 2 种解决方案。

  1. 大师解决方案:如果您是设计自己的专业人士 从头开始的 View / View 组(我的意思是,你了解方法 requestLayout()、dispatchDraw() 等),然后自己写 具有 3 个级别的 GrandExpandableListAdapter。
  2. 中等解决方案:对前 2 个级别使用 ExpandableListAdapter,对前 2 个级别使用 LinearLayouts 第三级。

关于android - 多层ExpandableListView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8293538/

相关文章:

android - 可扩展 ListView 组中的 2 行

java - 如何使用 arraylist 制作可扩展列表?

android - 在 Expandable listView android 中重复 child

android - 处理自定义首选项的长值

android - AIR mobile 始终处于横向状态

java - 获取用户在线/离线状态

android - 可扩展 ListView ;添加 itms 会弄乱展开的项目

android - annotationProcessor + androidTest + dagger2

java - 可扩展 ListView subview 问题

Android 可扩展 ListView : set background color of selected item on click