2

I am implementing a searchview for my app. Here is how i set my searchview:

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.options_menu, menu);
    this.menu = menu;

    // Associate searchable configuration with the SearchView
    SearchManager searchManager =
            (SearchManager) getSystemService(Context.SEARCH_SERVICE);
    MenuItem searchItem = menu.findItem(R.id.search);
    SearchView searchView = (SearchView) MenuItemCompat.getActionView(searchItem);
    searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
    searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
        @Override
        public boolean onQueryTextSubmit(String query) {
            return false;
        }

        @Override
        public boolean onQueryTextChange(String query) {
            loadHistory(query);
            return true;
        }
    });


    return true;

}

I want to show search suggestions to user when user starts typing. I can do this using a listview:

 private void loadHistory(String query) {

    // query db etc...

    SearchManager manager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
    final SearchView search = (SearchView) menu.findItem(R.id.search).getActionView();
    search.setSuggestionsAdapter(new ExampleAdapter(this, cursor, items));
}

But suppose I do not want to show search suggestions as a listview, and show them in a custom view, where I can add some more stuff to my layout other then just search suggestions. For example, I want to show the following custom view instead of suggested searches listview:

enter image description here

How can I do that? There is a function for setting suggestions adapter, setSuggestionsAdapter(adapter), but I could not find a function like setCustomSuggestionsView(view).

Thanks.

yrazlik
  • 10,411
  • 33
  • 99
  • 165

1 Answers1

0

I think what you need is a recycler view for your results. Please see this answer for more information. A recycler view gives you all the freedom layout wise. To use more viewtypes see this post. Hope this helps. I am not familliar enough with your case from your description.

Community
  • 1
  • 1
jobbert
  • 3,297
  • 27
  • 43
  • It is not the same, the asker needs suggestionAdapter for searchView not recyclerView edited by searchView. – adnbsr May 26 '16 at 14:45