Android内容提供商更新某些列 [英] Android content provider update certain columns

查看:93
本文介绍了Android内容提供商更新某些列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am trying to make an android application that will identify how much time is left for a task to be completed. I have followed Vogella's tutorial, particularly this part http://www.vogella.com/articles/AndroidSQLite/article.html#todo to make a contentprovider and database. It populates a listview with two things, the name of the task and how many days are left (the latter is calculated when the user selects his end date in another activity). My app calcualtes the current date and subtracts it from the end date and stores how many days are left in the database. The problem is that this is only stored once. Three days from now it will still say 4 days left. I want the app to check for how many days are left every time the client starts it (check current date, subtract from end date and update that column in the database). The problem is I'm not sure how to do it. If somebody could give me some guidance I would appreciate it.

推荐答案

进行计算,然后进行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

显然,您需要用正确的列名替换内容

obviously you will need to replace stuff with the correct column names

这篇关于Android内容提供商更新某些列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆