我对在我的 Android 应用程序中搜索感到困惑。我ListView
用我的ContentProvider
. 我集成了一个搜索视图。这很好用,但如果用户在搜索中输入字符串,则会调用错误的 URI:
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);
}
该应用程序崩溃并带有"NumberFormatException"
. 例如,我在搜索字段中输入“a”。据我研究过 google-dev 网站,这个 URI 应该被称为:+"/*",
实际上"/#"
调用了 URI,并抛出了异常。
知道我做错了什么吗?