2013-07-29 96 views
0

我要刪除「TYPE = 0」的記錄,我的代碼:getContentResolver()刪除過濾器不會影響

cv.put(Call.NAME, titleString); 
cv.put(Call.BUILD_NAME, ""); 
cv.put(Call.BUILD, build); 
cv.put(Call.UNIT, unit); 
cv.put(Call.ROOM, room); 
cv.put(Call.TIME, date); 
cv.put(Call.TYPE, 0);// 
cv.put(Call.DEVICETYPE, doordevicetype); 
cv.put(Call.PHOTO, baos.toByteArray()); 
cv.put(Call.CONTACT_ID, 9999); 

Uri contactUri, uriRet; 
ContentResolver resolver = getContentResolver(); 
uriRet = resolver.insert(contactUri, cv); 

這樣我就可以插入多條記錄,有的記錄Call.TYPE=0,一些Call.TYPE=1,所以我想全部刪除Call.TYPE=1。我的代碼:

int a=getContentResolver().delete(Call.CONTENT_URI, Call.TYPE +"=" +1, null); 

,但應用程序中刪除所有記錄,包括Call.TYPE=0。我不知道什麼是錯的。添加,插入,更新記錄一切正常,但刪除一些不起作用的reocrds,請給我一些建議嗎?

回答

2

使用此代碼刪除特定的行匹配時TYPE = 1 ...

String[] selectionArgs=new String[]{String.valueOf(1)}; 
// this is for which argument to match with TYPE=1 and delete row 

String selection=""+TablenName.TYPE+"=?"; // this is where condition 
getContentResolver().delete(Call.CONTENT_URI, selection, selectionArgs); 

Note : just refer this [link][1]. its usefull to understand for , how delete are happening.. 
[1]: http://www.w3schools.com/sql/sql_delete.asp 
+0

感謝您的回答,但它也刪除所有記錄。 – pengwang

+0

對不起,您的代碼是正確的 – pengwang

+0

偉大的答案+1 –