Java Android应用程序中未显示自定义搜索建议

Java Android应用程序中未显示自定义搜索建议,java,android,android-layout,Java,Android,Android Layout,我尝试了谷歌的以下指南:。我的应用程序的搜索功能正常工作,但无法显示搜索建议 如果在SearchView处于活动状态时键入内容,则它根本不会显示任何建议。例如,我得到了3个项目,其中包含worldHello。当我输入hello时,我希望在SearchView下面会出现某种listview。没有。是因为我在数据库中还没有太多的内容吗 这就是我到目前为止得到的。如果你能指出我错过了什么,那就太好了 Android清单文件: <?xml version="1.0" encoding="utf-8

我尝试了谷歌的以下指南:。我的应用程序的搜索功能正常工作,但无法显示搜索建议

如果在SearchView处于活动状态时键入内容,则它根本不会显示任何建议。例如,我得到了3个项目,其中包含world
Hello
。当我输入hello时,我希望在SearchView下面会出现某种listview。没有。是因为我在数据库中还没有太多的内容吗

这就是我到目前为止得到的。如果你能指出我错过了什么,那就太好了

Android清单文件:

<?xml version="1.0" encoding="utf-8"?>

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.neonwarge.android.note"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="15"
        android:targetSdkVersion="23" />

    <application
        android:name=".NoteApplication"
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >

        <activity
            android:name=".activities.HomeScreenActivity"
            android:label="@string/app_name">

            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>            

            <meta-data
                android:name="android.app.searchable"
                android:resource="@xml/searchable" />

        </activity>

        <activity
            android:name="com.neonwarge.android.note.activities.NoteActivity"
            android:label="@string/activity_label_note"
            android:launchMode="singleTop" >

            <meta-data
                android:name="android.support.PARENT_ACTIVITY"
                android:value="com.neonwarge.android.note.activities.HomeScreenActivity" />

        </activity>

        <activity
            android:name="com.neonwarge.android.note.activities.NoteSettingsActivity"
            android:label="@string/activity_label_notesettings" >

            <meta-data
                android:name="android.support.PARENT_ACTIVITY"
                android:value="com.neonwarge.android.note.activities.NoteActivity" />

        </activity>

        <activity
            android:name="com.neonwarge.android.note.activities.SearchResultActivity"
            android:label="@string/title_activity_search_result"
            android:launchMode="singleTop">

            <intent-filter>
                <action android:name="android.intent.action.SEARCH" />
            </intent-filter>

            <meta-data
                android:name="android.support.PARENT_ACTIVITY"
                android:value="com.neonwarge.android.note.activities.HomeScreenActivity"/>

            <meta-data
                android:name="android.app.searchable"
                android:resource="@xml/searchable" />

            <meta-data
                android:name="android.app.default_searchable"
                android:value="com.neonwarge.android.note.activities.SearchResultActivity"/>

        </activity>

        <receiver android:name=".receivers.NoteAlarmReceiver" />

        <provider
            android:name="com.neonwarge.android.note.providers.NoteProvider"
            android:authorities="com.neonwarge.android.note.providers.NoteProvider"
            android:exported="false"
            android:multiprocess="true" />       

    </application>

</manifest>
Searchable.xml:

<?xml version="1.0" encoding="utf-8"?>

<searchable xmlns:android="http://schemas.android.com/apk/res/android"
    android:label="@string/app_name"
    android:hint="@string/search_hint"    
    android:searchSuggestAuthority="com.neonwarge.android.note.providers.NoteProvider"
    android:searchSuggestIntentAction="android.intent.action.VIEW"
    android:voiceSearchMode="showVoiceSearchButton|launchRecognizer"
    android:searchSuggestSelection="ShortNote MATCH ? and LongNote MATCH ?">
</searchable>
我把SearchableDictionary示例加载到了我的工作区中,我相信我已经找到了每个位置。也许我以为这里出了什么事?显示建议的列表是否需要适配器?因为我已经提供了一个,它仍然没有显示。或者在建议生效之前,我需要一百万的内容。另外,我只是重复使用了我现有的内容提供商,我必须使用其他提供商吗


请让我知道我错过了什么。

这里有一个非常非常小的问题。我输入了“错误”的sql语法来查询虚拟表

我最初是这样键入的:
“ShortNote MATCH?and LongNote MATCH?”
这是错误的,因为我的表没有命名为ShortNote and LongNote。我应该使用以下语法:

FTS3\u表匹配的名称?

我误解了android:searchSuggestSelection,忘记了我使用FTS3表查找一些数据,错误地将其作为普通表进行查询

我所做的只是为android:searchSuggestSelection提供了一个非空值,并在ContentProvider中自己处理where子句,相关建议列表现在显示在搜索小部件/搜索对话框下面


谢谢大家!

这是一个非常非常小的问题。我输入了“错误”的sql语法来查询虚拟表

我最初是这样键入的:
“ShortNote MATCH?and LongNote MATCH?”
这是错误的,因为我的表没有命名为ShortNote and LongNote。我应该使用以下语法:

FTS3\u表匹配的名称?

我误解了android:searchSuggestSelection,忘记了我使用FTS3表查找一些数据,错误地将其作为普通表进行查询

我所做的只是为android:searchSuggestSelection提供了一个非空值,并在ContentProvider中自己处理where子句,相关建议列表现在显示在搜索小部件/搜索对话框下面


谢谢大家!

我在链接中发布了15行代码?你看到我的链接了吗?我也在使用自定义的SimpleCorsorAdapter,那交易是什么?我的15行代码是否运行了?那么告诉我为什么我发布了这些代码?不起作用的代码?原因是什么?什么不起作用?有什么原因吗?我看不出你的答案中有任何东西,为什么你不能用
runQueryOnBackgroundThread
方法返回数据我不知道你在说什么:如果你从ContentProvider返回光标#query或CursorAdapter#runQueryOnBackgroundThread,不同之处在于,您的代码有100行代码:(自定义ContentProvider、searchable.xml、清单中的更改等),而我的代码有15行,选择是我在链接中发布的15行代码?你看到我的链接了吗?我也在使用自定义的SimpleCorsorAdapter,那交易是什么?我的15行代码是否运行了?那么告诉我为什么我发布了这些代码?不起作用的代码?原因是什么?什么不起作用?有什么原因吗?我看不出你的答案中有任何东西,为什么你不能用
runQueryOnBackgroundThread
方法返回数据我不知道你在说什么:如果你从ContentProvider返回光标#query或CursorAdapter#runQueryOnBackgroundThread,不同之处在于,您的代码有100行代码:(自定义ContentProvider、searchable.xml、清单中的更改等),而我的代码有15行,由您选择
<?xml version="1.0" encoding="utf-8"?>

<searchable xmlns:android="http://schemas.android.com/apk/res/android"
    android:label="@string/app_name"
    android:hint="@string/search_hint"    
    android:searchSuggestAuthority="com.neonwarge.android.note.providers.NoteProvider"
    android:searchSuggestIntentAction="android.intent.action.VIEW"
    android:voiceSearchMode="showVoiceSearchButton|launchRecognizer"
    android:searchSuggestSelection="ShortNote MATCH ? and LongNote MATCH ?">
</searchable>
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater)
{
    super.onCreateOptionsMenu(menu,  inflater);
    inflater.inflate(mIsOnSearchMode? R.menu.fragment_search_result : R.menu.fragment_note_list, menu);

    SearchManager searchManager = (SearchManager) getActivity().getSystemService(Context.SEARCH_SERVICE);
    SearchView searchView = (SearchView) menu.findItem(R.id.menu_item_search).getActionView();
    searchView.setSearchableInfo(searchManager.getSearchableInfo(new ComponentName(getActivity().getPackageName() , SearchResultActivity.class.getName())));

    searchView.setSuggestionsAdapter(new SimpleCursorAdapter(getActivity(),
            android.R.layout.simple_list_item_1,
            null,
            new String[]{SearchManager.SUGGEST_COLUMN_TEXT_1 , SearchManager.SUGGEST_COLUMN_TEXT_2},
            new int[]{android.R.layout.simple_list_item_1},
            0));

    searchView.setIconifiedByDefault(true);
}