Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/207.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android:saerchable.xml和searchSuggestThreshold参数_Android_Android Searchmanager - Fatal编程技术网

Android:saerchable.xml和searchSuggestThreshold参数

Android:saerchable.xml和searchSuggestThreshold参数,android,android-searchmanager,Android,Android Searchmanager,我的项目中有一个搜索功能。在searchable.xml中,我希望仅当用户键入至少3个字符时才限制搜索 这可以通过android:searchSuggestThreshold=“3”来完成,但在我的例子中,什么都没有发生,用户仍然可以在键入一个或多个字符时执行搜索 以下是我的searchable.xml: <searchable xmlns:android="http://schemas.android.com/apk/res/android" android:label="@st

我的项目中有一个搜索功能。在searchable.xml中,我希望仅当用户键入至少3个字符时才限制搜索

这可以通过android:searchSuggestThreshold=“3”来完成,但在我的例子中,什么都没有发生,用户仍然可以在键入一个或多个字符时执行搜索

以下是我的searchable.xml:

<searchable xmlns:android="http://schemas.android.com/apk/res/android"
    android:label="@string/Label"
    android:hint="@string/Hint"
    android:searchSuggestThreshold="3"
    android:includeInGlobalSearch="true"/>

以下是清单中的2个搜索活动

 <activity android:name=".Search"
        android:configChanges="orientation|keyboardHidden">
          <intent-filter>   
        <action android:name="android.intent.action.SEARCH" />
        </intent-filter>
        <meta-data android:name="android.app.searchable"
               android:resource="@xml/searchable"/>   
        </activity>

         <activity android:name=".SearchInterface"
        android:configChanges="orientation|keyboardHidden">
         <meta-data android:name="android.app.default_searchable"
               android:value=".Search" />
         </activity>

在回答您的问题之前,您必须在AndroidManifest中更改一件事

 <meta-data android:name="android.app.default_searchable"
               android:value=".Search" />

我希望你明白我的意思。如果有任何疑问,请告诉我

你好@rallat,谢谢你的回答。我尝试了第一种解决方案,但没有任何改变。如果您看一下本文:元数据在活动标记中,而不是在应用程序标记中。对于第二种解决方案,我认为这实际上是不可能的,因为当用户键入搜索按钮时,搜索活动将关闭,并打开一个新活动,我将在其中执行所有查询并显示结果。因此,当用户单击搜索按钮时,我需要检查输入长度。在应用程序标记之间写入元数据意味着可搜索活动可以从整个应用程序调用搜索。所以我知道我理解你在使用这个android:searchSuggestThreshold=“3”时遇到的问题,但是你没有使用SuggestThreshold,对吗?这就是阈值不起作用的原因。请查看带有建议的字典示例,您将了解如何创建检查android:searchSuggestThreshold参数的建议
public static Cursor getAutoCompleteCursor(String s) {
    Cursor cursor;
    if (s != null && s.length() > 2)
        cursor = searchAutoComplete(s);
    else
        cursor = null;
    return cursor;
}