如何在Android的搜索立即启动建议用户甚至开始打字之前, [英] How to launch suggestions immediately in Android searchable before the user has even started typing

查看:128
本文介绍了如何在Android的搜索立即启动建议用户甚至开始打字之前,的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我做的ContentProviders和检索配置一些研究。我已经成立了一个扩展内容提供商与提供从数据库在用户键入建议数据库的类。它使用搜索管理模式(而不是搜索查看)。

I'm doing some research on ContentProviders and Searchable configurations. I've set up a class that extends a Content Provider with a database that provides suggestions from a database as the user types. This uses the Search Manager paradigm (not a SearchView).

到现在为止,一切都很正常。

Up to this point, everything works great.

我想和做的,是有问题的是显示一些建议的 的用户开始前打字,他启动搜索之后。设置属性机器人:searchSuggestThreshold =0在searchable.xml只有当用户实际水龙头到搜索文本框发射后 - 我想显示的建议搜索已推出后立即(即不等待用户做其他东西)。

What I'd like to do and am having problems with is to display some suggestions before the user starts typing, after he launches the search. Setting the property 'android:searchSuggestThreshold="0" ' in the searchable.xml only works if the user actually taps into the search textbox after launching it - I would like to display suggestions immediately after the search has been launched (i.e. not wait for the user to do anything else).

任何想法?

编辑:什么我说的是在谷歌Play商店应用搜索功能的一个例子 - 权当用户点击放大镜搜索,最近的一份建议清单立刻弹出

An example of what I'm talking about is the search functionality in the Google Play Store app - right when a user taps the Magnifying glass for search, a list of recent suggestions immediately pops up.

推荐答案

花费很多时间在这之后,嗯,我终于找到了一种方法来实现我所需要的。这里的答案,所以也许更少的其他开发人员受苦:

Well after spending many hours on this I have finally found a way to achieve what I needed. Here's the answer so perhaps fewer other developers suffer:

在搜索查看有关搜索模式具有文本改变监听器,只有当文本更改做它火了有关建议的请求。显然,对于初始状态没有发生任何变化,因此它不会通过查询()函数请求建议。

The SearchView for the search mode has a text changed listener, and only when the text changes does it fire off a request for suggestions. Obviously, for the initial state nothing has changed so it doesn't request suggestions through the query() function.

在以欺骗搜索查看,以为文本已经改变,你可以做到以下几点:

In order to "trick" the SearchView into thinking the text has changed, you can do the following:

@Override
public boolean onSearchRequested()
{
  final SearchManager searchManager = (SearchManager) getSystemService( SEARCH_SERVICE );    

  searchManager.startSearch( " ", true, getComponentName(), null, false );

  return super.onSearchRequested();
}

这篇关于如何在Android的搜索立即启动建议用户甚至开始打字之前,的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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