6

我正在尝试制作一个 android 应用程序,该应用程序将确定完成任务还剩多少时间。我遵循了 Vogella 的教程,特别是这部分http://www.vogella.com/articles/AndroidSQLite/article.html#todo制作内容提供者和数据库。它用两件事填充列表视图,任务名称和剩余天数(后者是在用户在另一个活动中选择结束日期时计算的)。我的应用程序计算当前日期并从结束日期中减去它并存储数据库中剩余的天数。问题是它只存储一次。从现在开始的三天后,它仍然会说还剩 4 天。我希望应用程序检查每次客户端启动它时还剩下多少天(检查当前日期,从结束日期中减去并更新数据库中的该列)。问题是我不知道该怎么做。如果有人能给我一些指导,我将不胜感激。

4

1 回答 1

17

做计算然后做getContentResolver().update(uri,values,selection,selectionArgs);

编辑:

所以只需更新值

ContentValues values = new ContentValues();
values.put(HabitTable.TIME); //whatever column you want to update, I dont know the name of it

...//any other values you want to update too

getContentResolver().update(HabitTable.CONTENT_URI,values,HabitTable.ID+"=?",new String[] {String.valueOf(id)}); //id is the id of the row you wan to update

显然你需要用正确的列名替换东西

于 2013-07-03T18:25:43.073 回答