Android – 带自定义建议的搜索对话框

weixin_38062043 2019-09-12 11:27:33
我有一个搜索对话框,需要从数据库启用建议,如http://developer.android.com/images/search/search-suggest-custom.png所示. 当我单击操作栏菜单项时,我的搜索对话框将显示在顶部.当用户开始输入某些文本时,它应该搜索数据库并相应地显示建议.截至目前,我有一个搜索对话框,但当用户键入某些文本时,不会显示任何建议. 我的内容提供商: public class MyCustomSuggestionProvider extends ContentProvider { SQLiteDatabase db; SQLiteQueryBuilder qb; String sqlTables = "countries"; @Override public int delete(Uri uri, String selection, String[] selectionArgs) { return 0; } @Override public String getType(Uri uri) { return null; } @Override public Uri insert(Uri uri, ContentValues values) { return null; } @Override public boolean onCreate() { return false; } public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) { MyDatabase myDB = new MyDatabase(getContext()); db = myDB.getReadableDatabase(); Cursor c = null; if (selectionArgs != null && selectionArgs.length > 0 && selectionArgs[0].length() > 0) { qb = new SQLiteQueryBuilder(); String[] sqlSelect = { "name" }; qb.setTables(sqlTables) c = qb.query(db, null, selection, selectionArgs, null, null, null); c.moveToFirst(); } else { return null; } return c; } @Override public int update(Uri uri, ContentValues values, String selection, String[] selectionArgs) { return 0; } } 我的清单: <application android:allowBackup="true" android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/Theme.Visa" > <provider android:name="com.m7.visa.contentprovider.MyCustomSuggestionProvider" android:authorities="com.m7.visa.contentprovider.MyCustomSuggestionProvider" > </provider> <activity android:name="com.m7.visa.MainActivity" android:label="@string/app_name" > <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> <intent-filter> <action android:name="android.intent.action.SEARCH" /> </intent-filter> <meta-data android:name="android.app.searchable" android:resource="@xml/searchable" /> </activity> </application> 我的可搜索配置: <?xml version="1.0" encoding="utf-8"?> <searchable xmlns:android="http://schemas.android.com/apk/res/android" android:hint="hint..." android:label="@string/app_name" android:searchSuggestAuthority="com.m7.visa.contentprovider.MyCustomSuggestionProvider" android:searchSuggestIntentAction="android.intent.action.VIEW" android:searchSuggestSelection=" ?" > </searchable> 知道我哪里错了吗?
...全文
71 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
weixin_38087180 2019-09-12
  • 打赏
  • 举报
回复
尝试删除android行的空格:searchSuggestSelection =“?” > 到android:searchSuggestSelection =“?” >

476

社区成员

发帖
与我相关
我的任务
社区描述
其他技术讨论专区
其他 技术论坛(原bbs)
社区管理员
  • 其他技术讨论专区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧