ListView 中的可扩展项
Expandable Items in ListView
我正在给自己写一个 ListView,它将包含多种类型的项目。我已经使用 ArrayAdapter and a ListView now my issue is that I need to have some Items inside my Adapter that is gonna expand and that will have inner items of any type. Now the issue is how can I do this? I know I can use ExpandableListView but I don't need some items to be expanded. I saw this post 做了类似的事情,有人建议使用 ExpandableListView 或自定义项,我想做自定义项,但我担心的是 OP的答案引用了这个。
If the number of items is low consider using a linearlayout to look
like a listview and another linearlayout for the last item.
我不确定他们说的 "low" 里面可以放多少东西?会造成滞后吗?
so my question is what is the best way to do this? I need to put items
in a ListView that is of multiple types, and one of the types can
expand and have inner views that can again contain the same types and
so on.
编辑:因为你们两个对我想要的东西感到困惑。我想在我的 ArrayAdapter
中执行以下操作
Item
Item
Item
ExpandableItem {
Item
Item
Item
Item
}
Item
Item
我正在尝试使一些项目展开以在其中包含更多项目并控制内部项目的 onClick 等。
在单击任何项目时添加另一个 ListView,例如 RecyclerView。
关于 "low" 的含义:我认为它与性能有关,但今天的设备比 2013 年编写链接 post 时的设备要好 - 也许您永远不会遇到迟钝的 UI 用你的方法。当然,这不仅取决于您的 UI 结构,还取决于您要显示的数据类型(视频还是文本?)以及其他因素,例如设备是否必须在后台执行繁重的工作或不是。
RecyclerView
被开发为 "better ListView
",因此如果性能可能成为问题,那么它也许是一个不错的选择。 (两个 ViewGroup
的适配器可以处理不同的 View
类型,但 RecyclerView
提供了一种更好的方法来显示对单个项目的更改和自定义更改动画,这是它的另一个优点)
How can I do this?
- 具有不同的
View
类型的可扩展项和平面项
- 你 可以 "manually" 通过使用某种类型的动画(或
Transition
框架),但你总是必须...
- 跟踪每个可扩展项目(例如在适配器中)的扩展状态,并分别在
getView()
中使用它们 onBindViewHolder()
。
我正在给自己写一个 ListView,它将包含多种类型的项目。我已经使用 ArrayAdapter and a ListView now my issue is that I need to have some Items inside my Adapter that is gonna expand and that will have inner items of any type. Now the issue is how can I do this? I know I can use ExpandableListView but I don't need some items to be expanded. I saw this post 做了类似的事情,有人建议使用 ExpandableListView 或自定义项,我想做自定义项,但我担心的是 OP的答案引用了这个。
If the number of items is low consider using a linearlayout to look like a listview and another linearlayout for the last item.
我不确定他们说的 "low" 里面可以放多少东西?会造成滞后吗?
so my question is what is the best way to do this? I need to put items in a ListView that is of multiple types, and one of the types can expand and have inner views that can again contain the same types and so on.
编辑:因为你们两个对我想要的东西感到困惑。我想在我的 ArrayAdapter
中执行以下操作Item
Item
Item
ExpandableItem {
Item
Item
Item
Item
}
Item
Item
我正在尝试使一些项目展开以在其中包含更多项目并控制内部项目的 onClick 等。
在单击任何项目时添加另一个 ListView,例如 RecyclerView。
关于 "low" 的含义:我认为它与性能有关,但今天的设备比 2013 年编写链接 post 时的设备要好 - 也许您永远不会遇到迟钝的 UI 用你的方法。当然,这不仅取决于您的 UI 结构,还取决于您要显示的数据类型(视频还是文本?)以及其他因素,例如设备是否必须在后台执行繁重的工作或不是。
RecyclerView
被开发为 "better ListView
",因此如果性能可能成为问题,那么它也许是一个不错的选择。 (两个 ViewGroup
的适配器可以处理不同的 View
类型,但 RecyclerView
提供了一种更好的方法来显示对单个项目的更改和自定义更改动画,这是它的另一个优点)
How can I do this?
- 具有不同的
View
类型的可扩展项和平面项 - 你 可以 "manually" 通过使用某种类型的动画(或
Transition
框架),但你总是必须... - 跟踪每个可扩展项目(例如在适配器中)的扩展状态,并分别在
getView()
中使用它们onBindViewHolder()
。