参数传递给自定义搜索建议的ContentProvider [英] Pass a parameter to a Custom Search Suggestion ContentProvider

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

问题描述

我有一个工作的自定义搜索建议类(通过 HTTP: //developer.android.com/guide/topics/search/adding-custom-suggestions.html )。目前,它返回一种信息 - 产品名称

I have a working custom search suggestions class (via http://developer.android.com/guide/topics/search/adding-custom-suggestions.html). It currently returns one type of information - "product names".

我添加了一些额外的活动(屏幕)我的应用程序,这样,如果一个人是一个产品页面上,启动一个搜索应该从产品名称返回的结果,但如果他们在另一个活动,我会像搜索建议来拉的制造商名称。

I've added some additional activities (screens) to my app so that if a person is on a product page, starting up a search should return results from "product names", but if they are in another activity, I would like the search suggestions to pull "manufacturer names".

我看了<一个href=\"http://stackoverflow.com/questions/4397349/accessing-appsearchdata-bundle-from-contentprovider\">Accessing从ContentProvider的 appSearchData捆绑,但自定义搜索建议提供程序扩展的ContentProvider不与答案工作

I saw Accessing appSearchData bundle from ContentProvider, but the custom search suggestions provider extends ContentProvider which doesn't work with the answer

Bundle b = intent.getBundleExtra(SearchManager.APP_DATA);

此软件包可在搜索结果的类,但不是ContentProvider的。

This Bundle is available to the search results class, but not the contentprovider.

如何以最佳方式参数(产品或制造商)传递给搜索建议内容提供商?

How best to pass a parameter ("product" or "manufacturer") to a search suggestions content provider?

推荐答案

这似乎不是一个理想的解决方案,但我有同样的需要,我发现我能得到这份工作,加入公共伊娃或方法做的ContentProvider的子类,处理搜索建议。在此之前启动搜索,您可以根据需要配置您的供应商。您可以从活动中访问提供程序实例,像这样:

This doesn't seem like an ideal solution, but I had the same need and I found I could get the job done by adding a public ivar or method to the subclass of ContentProvider that handles the search suggestions. Prior to initiating the search, you can configure your provider as needed. You can access the provider instance from an activity like so:

ContentProviderClient client = getContentResolver().acquireContentProviderClient("my.searchsuggestionprovider");
MyProviderClass provider = (MyProviderClass) client.getLocalContentProvider();

现在你可以用 provider.setParameter(产品)或任何你需要的配置。您可能需要建立你的光标后面的参数为默认或东西复位。

Now you can configure with provider.setParameter("product") or whatever you need. You might need to reset the parameter to a default or something after building your cursor.

编辑:事实证明,这是不切实际的,至少在我的情况下,由于内容提供商被调用,查询()每一个字符键入时。相反,我已经采用类似的是,在<一个描述的解决方法href=\"http://stackoverflow.com/questions/4011867/set-search-hint-dynamically/4422290#4422290\">set-search-hint-dynamically.通过创建一个备用搜索XML定义和活动,你可以改变的是传递给查询()内容提供商的URI,添加路径组件提供您所需要的附加参数或上下文。

This turned out to be impractical, at least in my case, since the content provider is called with query() every time a character is typed. Instead, I have employed a workaround similar to what is described in set-search-hint-dynamically. By creating an alternate "searchable" XML definition and activity, you can alter the URI that's passed to the content provider in query(), adding a path component to provide the additional parameter or context you need.

这篇关于参数传递给自定义搜索建议的ContentProvider的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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