简体   繁体   English

Android使用数据库中的有用数据填充ListView

[英]Android Populating ListView with wanted data from database

I have an Alarm Application which stores its alarms into a database so it can retrieve it ON_BOOT , now I'm thinking of implementing a display of all alarms, depending the day you select. 我有一个警报应用程序,它将警报存储到数据库中,以便可以在ON_BOOT检索它,现在我正在考虑实现根据所选日期显示所有警报的功能。 I have been thinking using a ListView and populating it with alarms. 我一直在考虑使用ListView并用警报填充它。 I have read that SimpleCursorAdapter is a way to go but I was wondering how would I populate so it displays only alarms which are set on Monday, for example? 我已经读过SimpleCursorAdapterSimpleCursorAdapter的方法,但是我想知道如何填充它,以便仅显示例如星期一设置的警报? It seems I would need to run a query somewhere but I'm not sure where. 似乎我需要在某个地方运行查询,但是我不确定在哪里。

You can run an SQL query that will only return alarms on a given date: 您可以运行一个SQL查询,该查询仅在给定日期返回警报:

SELECT * FROM alarms WHERE strftime( '%w', date_column ) = day

where "day" is a number corresponding to the day of the week (0=Sunday, 1=Monday, etc). 其中,“ day”是对应于星期几的数字(0 =星期日,1 =星期一,等等)。

If you're storing the date as just a day of the week, then it's easier: 如果将日期存储为一周中的某一天,那么会更容易:

SELECT * FROM alarms WHERE day_column = day

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

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