开发者

android app search button

I've been trying to make my app implement the built in quick search, similar to how it is done in ApiDemos' "app/search/invoke search". I have tried everything from trying to follow different examples, to copying the code exactly as it is in ApiDemos.

All I've found for the former have been concerned with older versions of the SDK, and simply not worked. As for the stuff that I can actually run and see working in ApiDemos, I've tried copying the f开发者_JAVA百科ollowing

com.example.android.apis.app.SearchInvoke.java
com.example.android.apis.app.SearchQueryResults.java
com.example.android.apis.app.SearchSuggestionSampleProvider.java

res/layout/search_invoke.xml
res/layout/search_query_results.xml
res/values/arrays.xml
res/values/strings.xml
res/xml/searchable.xml

... and everything under "Search Samples" in AndroidManifest.xml

This copying gets me a view that looks exactly like the one I'm facing when running ApiDemos, but when I click the search button, in the quick search box, Android always just opens up a browser window, with Google search results for the given query. I simply cannot find the critical component in ApiDemos that tells android that I want to use my own custom code for handling the search request.

I would really appreciate some help in this matter. Both documentation and other online resources seem very lacking when it comes to this.

Thanks.


For reference, four months (and god knows how many attempts) later, I've found the part of the documentation I've missed out on, that had the whole search box behave fire up browser search results, instead of passing them to my own activity. It all comes down to a little notice found here:

Note that all user-visible strings must be provided in the form of "@string" references. Hard-coded strings, which cannot be localized, will not work properly in search metadata.


Try reading this first. If that does not help, you can try looking at the search example from one of my books -- that example integrates with the Quick Search Box, and perhaps it will give you more clues.


In addition to the examples provided by commonsware.com, you can look at the Searchable Dictionary in the samples directory of the 1.6 SDK.

http://developer.android.com/guide/samples/SearchableDictionary/index.html


I was wrong before... the SDK documentation has a thurough explanation in the docs for SearchManager that I suggest you take a look at. In addition, as CommonsWare mentioned, the blog entry is also a good resource.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜