Android内容提供商更新某些列

时间:2013-07-03 18:21:51

标签: android database sqlite android-contentprovider

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

1 个答案:

答案 0 :(得分: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

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

相关问题