Android: saerchable.xml and searchSuggestThreshold parameter

I have a search function in my project. In the searchable.xml file, I would like to limit the search only when the user enters at least 3 characters.

This can be done using android: searchSuggestThreshold = "3", but in my case nothing happens, the user can still search when he types or more characters.

Here is my 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"/>

Here are 2 search operations from the manifest

 <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>
+5
source share
1 answer

Before answering your question, there is one thing that you must change in AndroidManifest.

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

<application></application>, <activity></activity>. , . , : searchSuggestThreshold. SearchHelper, (, SQL-), , if. :

public static Cursor getAutoCompleteCursor(String s) {
    Cursor cursor;
    if (s != null && s.length() > 2)
        cursor = searchAutoComplete(s);
    else
        cursor = null;
    return cursor;
}

, , . !

+5

All Articles