简体   繁体   English

如何比较和分组ArrayList对象

[英]How to compare and group an ArrayList Object

I am trying to group an ArrayList of event into a list of dates but have no idea how to achieve it. 我试图将事件的ArrayList分组为日期列表,但不知道如何实现。

My goal is to load the grouped data into an ExpandableListView see image below. 我的目标是将分组的数据加载到ExpandableListView请参见下图。

I have a list of dates and a list of events too. 我也有一个日期列表和一个事件列表。 So, I want to group the events objects into different days based on their date attributes. 因此,我想根据事件的日期属性将事件对象分为不同的日期。

exlistview

You have to convert your data in the way ExpandableListAdapter wants them. 您必须按照ExpandableListAdapter所需的方式转换数据。

Android has SimpleExpandableListAdapter that can be used but this does not look even a little to the screen you provided. Android具有可以使用的SimpleExpandableListAdapter ,但是在您提供的屏幕上看起来几乎没有。 Just for reference here is an Example using such an adapter, so you get a point how it works. 仅供参考, 这里是使用这种适配器的示例 ,因此您将了解其工作原理。

If you want something exactly as the screen you provided you have to implement a custom expandable listiview with ExpandableListAdapter by extending BaseExpandableAdapter 如果您想要的东西与您提供的屏幕完全相同,则必须通过扩展BaseExpandableAdapter来使用ExpandableListAdapter实现自定义可扩展BaseExpandableAdapter

In case the items under the dates does not expand-collapse by pressing then I strongly sugest to look for a ListView with Section Headers the implementations is much easier. 如果日期下的项目没有通过按键展开或折叠,那么我强烈建议您使用带有节标题ListView,实现起来会容易得多。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM