1

提案が有効になっている検索ウィジェットがあります。すべて問題なく動作しますが、提案を得るには単語全体を書かなければなりません。

- android:searchSuggestThreshold="2" を設定しましたが、提案を取得するには、単語 (5-6) 文字を終了する必要があります。なんで?

私は本当に、本当に助けていただければ幸いです。ありがとう!

マニフェスト:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.exploreca.tourfinder"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-permission android:name="android.permission.CALL_PHONE" />

    <uses-sdk
        android:minSdkVersion="14"
        android:targetSdkVersion="19" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_exploreca"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >     
        <activity
            android:name="com.exploreca.tourfinder.MainActivity"
            android:label="@string/app_name" >            
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>            
        </activity>
        <activity 
            android:name=".SettingsActivity">            
        </activity>
        <activity 
            android:name=".TourDetailActivity">            
        </activity>        
        <!-- Search results activity -->
        <activity android:name=".SearchActivity">
             <intent-filter>
                <action android:name="android.intent.action.SEARCH" />
            </intent-filter> 
            <meta-data
                android:name="android.app.searchable"
                android:resource="@xml/searchable" />
        </activity>  

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

        <provider
        android:name=".SearchContentProvider"
         android:authorities="com.exploreca.tourfinder.SearchContentProvider" >
     </provider>   

    </application>
</manifest>

そして、SearchContentProvider で使用されている部分:

@Override
public Cursor query(Uri uri, String[] projection, String selection, 
          String[] selectionArgs, String sortOrder) { 

    Log.i(LOGTAG, "The typed characters are: " + selectionArgs[0]);

        SQLiteQueryBuilder builder = new SQLiteQueryBuilder();
        builder.setTables(ToursDBOpenHelper.TABLE_TOURS);           

        HashMap<String, String> columnMap = new HashMap<String, String>();
        columnMap.put(BaseColumns._ID, ToursDBOpenHelper.COLUMN_ID + " AS " + BaseColumns._ID);
        columnMap.put(SearchManager.SUGGEST_COLUMN_TEXT_1, ToursDBOpenHelper.COLUMN_TITLE + " AS " + SearchManager.SUGGEST_COLUMN_TEXT_1);
        columnMap.put(SearchManager.SUGGEST_COLUMN_INTENT_DATA, ToursDBOpenHelper.COLUMN_ID + " AS " + SearchManager.SUGGEST_COLUMN_INTENT_DATA);
        builder.setProjectionMap(columnMap);

        dbhelper = new ToursDBOpenHelper(getContext());
        //database = dbhelper.getReadableDatabase();

        SQLiteDatabase db = dbhelper.getWritableDatabase();
        cursor = builder.query(db, projection, selection, selectionArgs, null, null, null, null);

        return cursor;
}

そして searchable.xml:

<?xml version="1.0" encoding="utf-8"?>
<searchable xmlns:android="http://schemas.android.com/apk/res/android"
    android:hint="@string/search_hint"
    android:label="@string/app_name" 
    android:searchSuggestAuthority="com.exploreca.tourfinder.SearchContentProvider"
    android:searchSuggestIntentAction="android.intent.action.VIEW"
    android:searchSuggestSelection="city LIKE ?" 
    android:searchSuggestThreshold="2"
    android:includeInGlobalSearch="true"/>
4

1 に答える 1