0

I am implementing a SearchView on ActionBar with ActionBarSherlock. I went through the documentation on this topic: http://developer.android.com/guide/topics/search/index.html but I am confused:

(1) It seems the framework pushes you to use ContentProvider for suggestions and SearchView retrieves the suggestions by calling the ContentProvider.query() method. However, I don't think I can use this framework because I will get my suggestions from a server. That is, I will provide a keyword to call an api, after the data is fetched, a callback function will be called. So it is async so that the query() method won't work. Can I get rid of the ContentProvider to implement the suggestions?

(2) My suggestion items should be customized. There will be a CheckBox in each item. So I think I should use a customized adapter. I only found a method setSuggestionAdapter() in SearchView which only receives CursorAdapter. From my knowledge, CursorAdapter is used for database query. However there is no database concept in my case.

(3) It seems you have to bind your SearchView to an Activity. Is it really necessary or can we bind it to a Fragment instead?

Any suggestions for this ? Thanks in advance!

darklord
  • 5,077
  • 12
  • 40
  • 65
  • 1
    ad 1) it will use default drop-down list so you can have customized items with check boxes, ad 2) yes, setSuggestionAdapter() will work, just use it with MatrixCursor, ad 3) que? what do you mean? – pskink May 13 '14 at 15:23
  • btw you could use ContentProvider as well but you cannot change the drop down used by default by SearchView – pskink May 13 '14 at 17:09
  • so what does the binding mean here? – pskink May 14 '14 at 05:38
  • @pskink I have a handler function for the search. In the documentation it says you should make an activity searchable. But it's meaningless to make an Activity searchable in my case. So I am thinking if we can make an Fragment searchable or nothing. – darklord May 14 '14 at 15:35
  • just set a SearchView as a custom view in a ActionBar, dont need to bind to anything – pskink May 14 '14 at 15:39
  • and what, did it work? – pskink May 15 '14 at 04:48
  • @pskink Thanks. I am trying to add a customized drop-down list to the action bar (An RelativeLayout with a search button, a AutoCompleteTextView and a clear button). Right now the UI side is working well (view expansion, drop-down list showing). I think the SearchView in Android framework is designed for the case of searching in database. It may not be a good idea to use it in my case (Display suggestions based on web api calls). – darklord May 15 '14 at 14:37
  • see my ad 2) you can use a std SerchView with no problem – pskink May 15 '14 at 14:41

0 Answers0