Android content provider update certain columns

风流意气都作罢 提交于 2019-12-22 07:15:29

问题


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.


回答1:


do the calculation then do getContentResolver().update(uri,values,selection,selectionArgs);

EDIT:

so just update with the values

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



来源:https://stackoverflow.com/questions/17455482/android-content-provider-update-certain-columns

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!