2012-12-19 57 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的字符串不是空的条件被附加到 分贝删除操作。