gpt4 book ai didi

android - 使用游标填充后将项目添加到 ListView

转载 作者:行者123 更新时间:2023-11-30 03:24:23 25 4
gpt4 key购买 nike

在我的(第一个)android 应用程序上,我有一个日记屏幕,其中显示了用户的约会列表。目前,该应用程序显示一个约会列表,其中显示了列表中的核心信息(开始时间、结束时间等)。

为了让用户看到他们在约会之间什么时候有空闲时间,他们需要煞费苦心地查看所有时间,并在有空档的时候计算出来。我想在视觉上创建这个间隙,让用户更直观。

目前我正在使用 SimpleCursorAdapter 从 SQLite 表中填充 ListView ,但据我所知,我无法编辑游标的结果(因为 - 据我所知 - 游标只是指向数据库的指针,不是信息的副本)。

理想情况下,我想做的是检测约会之间是否存在间隙,并在存在间隙的地方插入额外的一行(无论间隙的大小 - 只是一行)。我希望这个“间隔”行说明间隔包含多少分钟的空闲时间。

实现此目标的最佳方法是什么?

我在下面添加了我理想的布局:

enter image description here

最佳答案

您可以预约类(class):

class Appointment implements Comparable<Appointment> {

// your appointment class

private String title;
private Date time;
private boolean isFreeTime;
etc.

Constructor
Setters/Getters

@Override
public int compareTo(Appointment appointment) {
return 0; //Here you sort by date or whatever you want
}
}

在设置适配器之前通过光标。

ArrayList<Appointment> appointments = new ArrayList<Appointment>();

if (cursor == null)
return;

cursor.moveToFirst();

while (!cursor.isAfterLast()) {

Appointment appointment = new Appointment(/*your stuff*/);
appointments.add(appointment);

cursor.moveToNext();

}

cursor.close();

然后浏览列表并添加所有空闲时间行。

appointments.setFreeTime(true);

使用

Collections.sort(appointments);

扩展 BaseAdapter 并将 ArrayList 传递给该适配器

这应该有效:)

关于android - 使用游标填充后将项目添加到 ListView ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18514091/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com