Update item in database without all of the columns set in ContentValues

前提是你 提交于 2019-12-03 09:12:50

To answer your question, yes you can pass just one field of data to the update and it will update that column without affecting any others.

The problem you currently have, by the looks of it, you are not telling the DB which record you want to update.

As per the update method:

public int update (String table, ContentValues values, String whereClause, String[] whereArgs)

You are passing null for the where part of the method.

If you pass a where part to the method it will update just the specific entry(s).

ContentValues values = new ContentValues();
values.put(MyPerson.PHONE_NUMBER, "222-222-2222");
getContentResolver().update(tedUri, values, "first_name = ?", new String[] { "tom" });

Would update anyone with the first name tom to have the phone number 222-222-2222

That would work exactly as you described, only set values will be updated.

You can set where clause in update function 3rd parameter

getContentResolver().update(tedUri, values, "first_name=?", new String
         [ ]{"name"});
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!