android app search button
Asked Answered
M

4

6

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 following

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.

Metamathematics answered 18/10, 2009 at 13:51 Comment(0)
M
10

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.

Metamathematics answered 23/2, 2010 at 21:28 Comment(2)
Wow, thanks. That is exactly what fixed my issue -- it would not accept hard-coded string values while I was testing. I simply converted it to use refs in strings.xml and it works not.Oligochaete
@David Thanks a lot. I was stuck up for more than a day just because I had hardcoded strings. Thanks once more. :)Mcquade
S
1

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.

Syllabary answered 18/10, 2009 at 14:17 Comment(5)
Hi. Thanks for your comment, but neither the resources you've linked to, or the example code you've provided, seems to work for me. The search button invokes the global search ui, which is what i want, but typing anything in it only yields the default suggestions, and hitting the search button always opens up a web view. What I want is to capture the click of the search button, and generate a result view of my own. I don't even need a suggestion provider, if I can just get the search working. Surely, this should be quite doable...?Metamathematics
No, it is not doable, short of modifying the firmware, or perhaps writing a replacement home app with a search box that behaves the way you want.Syllabary
Then, is this not what, say, Market is doing? Or the Search Invoke demo in ApiDemos. They are both examples of searches that appear at the click of the device's search button, and when the button is clicked in the view that appears, they generate their own result view, rather than opening a webview with regular google search results...?Metamathematics
If one of the API Demos does what you want, grab the code for that API demo -- it is in your SDK. At least in the case of the Android Market, that's not the Quick Search Box, but rather their own search box for a local search, AFAICT.Syllabary
In that case I might have used the wrong terminology, and a local search might indeed be what I want. Either way, what I have not found a way to avoid is for the web view to be loaded when the search button is clicked. I have copied everything I can possibly find in the API Demos, but I still have not found the critical piece of code that lets me control the search results myself, rather than opening the browserMetamathematics
K
0

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

Keating answered 18/10, 2009 at 19:12 Comment(0)
H
0

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.

Harmaning answered 19/10, 2009 at 22:47 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.