2017-01-23 81 views
0

如果我有與列的表:我需要爲每列添加adduri嗎?

COMPANION_ID 

COMPANION_NAME 

COMPANION_TYPE 

做我需要做的

uriMatcher.addURI(AUTHORITY,"COMPANION/#",COMPANION_ID); 
uriMatcher.addURI(AUTHORITY,"COMPANION/*",COMPANION_NAME); 
uriMatcher.addURI(AUTHORITY,"COMPANION/*",COMPANION_TYPE); 

或做我做的:

uriMatcher.addURI(AUTHORITY,"COMPANION/COMPANION_ID/#",COMPANION_ID); 
uriMatcher.addURI(AUTHORITY,"COMPANION/COMPANION_NAME/*",COMPANION_NAME); 
uriMatcher.addURI(AUTHORITY,"COMPANION/COMPANION_TYPE/*",COMPANION_TYPE); 
+0

你需要查詢/刪除由「名」和/或「輸入」 /更新? – pskink

+0

@pskink是的我需要 –

+0

所以請按照路徑#2 – pskink

回答

0

我覺得你有點困惑關於UriMatchers。使用投影來獲取查詢中的列,使用UriMatchers來區分內容提供者中的路徑。

要獲取ID的伴侶我會用yourfirst URI匹配

  • uriMatcher.addURI(AUTHORITY, 「伴侶/#」,COMPANION_ID);

後,我將使用投影識別每個柱:

//查詢用戶字典並返回結果 mCursor = getContentResolver()的查詢( yourUri,//內容的URI。 COMPANION表,帶您的ID mProjection,//每行返回的列 mSelectionClause //選擇條件 mSelectionArgs,//選擇條件 mSortOrder); //爲返回的行

的排序順序看看這裏澄清:https://developer.android.com/guide/topics/providers/content-provider-basics.html