0

I have added a searchView in my toolbar and I would like to show a dropdown as android does with the AutoCompleteTextView.

So basically I want to display a list of result and change it while the user is typing. I have added already a function to filter my results, but I have no clue how to show the dropdown in the list using my searchView.

Take a look the code below:

 @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.menu_subs, menu);

        MenuItem searchItem = menu.findItem(R.id.action_search);
        SearchView searchView = (SearchView) MenuItemCompat.getActionView(searchItem);

        searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener(){

            @Override
            public boolean onQueryTextSubmit(String query) {
                return false;
            }

            @Override
            public boolean onQueryTextChange(String newText) {
                //TODO: Implement dropdown 
                _list = _repository.filterItems(newText);
                return false;
            }
        });

        return true;
    }

NOTE: something like in the image, I want to show my results(list of strings) in the dropdown.

enter image description here

any idea? Thanks!

gon250
  • 3,405
  • 6
  • 44
  • 75

1 Answers1

0

you should add this code in your onCreateOptionsMenu

    SearchAutoComplete autoCompleteTextView = (SearchAutoComplete) searchView.findViewById(R.id.search_src_text);

if (autoCompleteTextView != null) { 
    autoCompleteTextView.setDropDownBackgroundResource(R.drawable.abc_search_dropdown_light);
}

For more information check this link

How to build Gmail like search box in the action bar?

Community
  • 1
  • 1
Amir_P
  • 8,322
  • 5
  • 43
  • 92