2013-10-12 52 views
0

我對在我的Android應用程序中搜索感到困惑。我使用我的ContentProvider中的數據填充ListView。 我集成了一個搜索視圖。這工作得很好,但如果用戶輸入的搜索字符串,錯誤的URI被稱爲:用"NumberFormatException"Android:在ListView中用ContenProvider搜索

switch(sURIMatcher.match(uri)) { 
     case RP_ENTRY_DIRECTORY: 
      break; 
     case RP_ENTRY_DIRECTORY_FILTER: 
      queryBuilder.appendWhere(RpEntry.Columns.SNAME + " LIKE %"+ uri.getLastPathSegment()+"% "); 

     case RP_ENTRY_ITEM: 
      long id = ContentUris.parseId(uri);    
      queryBuilder.appendWhere(RpEntry.Columns.SNAME + " LIKE "+ uri.getLastPathSegment()); 

//    if(selection!=null && !selection.isEmpty()) 
//     _selection += " and"+selection; 
//    return dbhelper.getReadableDatabase().query(RpEntry.TABLE_NAME, 
//      projection, _selection, selectionArgs, null, null, sortOrder); 
       break; 


private static final UriMatcher sURIMatcher = 
     new UriMatcher(UriMatcher.NO_MATCH); 

static { 
    sURIMatcher.addURI(AUTHORITY, RpEntry.CONTENT_DIRECTORY, RP_ENTRY_DIRECTORY); 
    sURIMatcher.addURI(AUTHORITY, RpEntry.CONTENT_DIRECTORY+"/*", RP_ENTRY_DIRECTORY_FILTER); 
    sURIMatcher.addURI(AUTHORITY, RpEntry.CONTENT_DIRECTORY+"/#", RP_ENTRY_ITEM);   
} 

應用崩潰。例如。我在搜索字段中輸入'a'。據我研究谷歌開發網站,這個URI應該被稱爲:+"/*",

事實上,調用的URI "/#",並拋出異常。

任何想法我做錯了什麼?

+2

請編輯並正確格式化您的問題。 –

回答

0

看起來你錯過了RP_ENTRY_DIRECTORY_FILTER案例中的break語句。