2012-12-19 60 views
1

幾個概念,我無法理解在下面的代碼中的某些概念:瞭解的內容提供商

1)爲什麼我們using.arg0.getPathSegments()得到(1)?

2)get(1)的值是多少?

3)什麼是 (!TextUtils.isEmpty(arg1)?「AND(」+ arg1 +')':「」),arg2);

public int delete(Uri arg0, String arg1, String[] arg2) { 
    int count=0; 
    switch (uriMatcher.match(arg0)){ 
    case BOOKS: 
     count = booksDB.delete(
      DATABASE_TABLE, 
      arg1, 
      arg2); 
     break; 
    case BOOK_ID: 
     String id = arg0.getPathSegments().get(1); 
     count = booksDB.delete(
      DATABASE_TABLE,       
      _ID + " = " + id + 
      (!TextUtils.isEmpty(arg1) ? " AND (" + 
      arg1 + ')' : ""), 
      arg2); 
     break; 
    default: throw new IllegalArgumentException(
     "Unknown URI " + arg0);  
    }  
    getContext().getContentResolver().notifyChange(arg0, null); 
    return count;  
+0

1 /閱讀文檔。這是第二條路徑。看看uri格式,這應該是有道理的。 2 /調試它或記錄它,這取決於arg0 Uri 3 /這是一個三元符號。它用於在arg1上添加一個條件爲arg1存在。 – njzk2

回答

0

1)爲什麼我們使用using.arg0.getPathSegments()。get(1)?

假設你與URI查詢內容:// [管理局] /富/酒吧 getPathsegments將返回與foo和bar(不 機關)

2)名單有何價值得到(1)?

因此,對於上述情況得到(1)會給你第二個項目的名單上即 酒吧

3)什麼是功能性(!TextUtils.isEmpty(ARG1)嗎?「( 「+ arg1 +')':」「),arg2);

刪除功能簽名

public int delete(Uri url, String where, String[] whereArgs) 

所以,如果where的字符串不是空的條件被附加到 分貝刪除操作。