最近的搜索不显示,自定义的建议是 [英] recent searches are not displayed, custom suggestions are

查看:109
本文介绍了最近的搜索不显示,自定义的建议是的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个搜索窗口小部件(搜索查看),显示自定义的建议,同时打字。我已经按照<一href=\"http://developer.android.com/guide/topics/search/adding-recent-query-suggestions.html\">official指南最近查询添加到的建议,但我仍然有定制的建议而已。结果
对于每个搜索,我的片段调用这个函数(验证):

I have a search widget (SearchView), displaying custom suggestions while typing. I've followed official guide to add recent queries to suggestions, but I still have custom suggestions ONLY.
For each search, my fragment call this function (verified) :

private void addQueryToRecent(String query) {
    SearchRecentSuggestions suggestions = new SearchRecentSuggestions(getActivity(),
            MyCustomSuggestionProvider.AUTHORITY,
            MyCustomSuggestionProvider.MODE);
    suggestions.saveRecentQuery(query, "recent");
}

我的建议提供者似乎确定:

My suggestion provider seems ok :

public class MyCustomSuggestionProvider extends SearchRecentSuggestionsProvider {

public final static String AUTHORITY = "com.zgui.musicshaker.provider.MyCustomSuggestionProvider";
public final static int MODE = DATABASE_MODE_QUERIES | DATABASE_MODE_2LINES;

public MyCustomSuggestionProvider() {
    setupSuggestions(AUTHORITY, MODE);
}

@Override
public Cursor query(Uri uri, String[] projection, String sel,
        String[] selArgs, String sortOrder) {
    //retrieves a custom suggestion cursor and returns it
}
}

searchable.xml:

searchable.xml :

<?xml version="1.0" encoding="utf-8"?>
<searchable xmlns:android="http://schemas.android.com/apk/res/android"
android:hint="artist, track informations..."
android:label="@string/app_name"
android:queryAfterZeroResults="true"
android:searchSuggestAuthority="com.zgui.musicshaker.provider.MyCustomSuggestionProvider"
android:searchSuggestSelection=" ?" />

清单:
    
            
                

manifest :

            <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>
<provider
        android:name=".provider.MyCustomSuggestionProvider"
        android:authorities="com.zgui.musicshaker.provider.MyCustomSuggestionProvider"
        android:enabled="true" >
    </provider>

Acording到<一个href=\"http://stackoverflow.com/questions/6270648/where-does-android-store-search-term-history-for-our-search-enabled-activities\">that帖子,我应该有在数据/数据​​/ app.package.name /数据库/ databasename.db最近的搜索分贝,但我似乎并不...结果
或者,也许我应该补充的游标MyCustomSuggestionProvider.query()返回最近的搜索建议自己?任何想法是值得欢迎的...

Acording to that post, I'm supposed to have a recent search db at data/data/app.package.name/databases/databasename.db, but I don't seem to...
Or maybe am I supposed to add the "recent search suggestions" myself in the cursor that MyCustomSuggestionProvider.query() returns ? Any idea is welcome...

推荐答案

发现:这不是扣片在Android文档可言,但我需要让自己的要求和MyCustomSuggestionProvider.query合并光标()..

found it : it wasn't cleat at all on android documentation, but I need to make the request myself and merge cursors in MyCustomSuggestionProvider.query()...

Cursor recentCursor = super.query(uri, projection, sel, selArgs,
            sortOrder);
Cursor[] cursors = new Cursor[] { recentCursor, customCursor};
return new MergeCursor(cursors);

请确保您有相同的列在这两个虽然...

make sure you have the same columns in both though...

这篇关于最近的搜索不显示,自定义的建议是的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆