How to make a drop-down list of search SearchView in SearchView ?

According to this type, when a person began to introduce something, the search options are shown.

drop down list in searchview

1 answer 1

Listeners

 searchView.setOnQueryTextListener(new android.support.v7.widget.SearchView.OnQueryTextListener() { @Override public boolean onQueryTextSubmit(String query) { return true; } @Override public boolean onQueryTextChange(String newText) { loadHistory(String query) ; return true; } }); 

With this method you can display a drop-down list. When we want to add or delete data, we add and delete them in the listeners, but do not forget to update the adapter.

 private List<String> items; items = new ArrayList<>(); //проверка items.add("test 1 "); items.add("test 2"); items.add("Марина"); private void loadHistory(String query) { if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { // Cursor String[] columns = new String[] { "_id", "text" }; Object[] temp = new Object[] { 0, "default" }; MatrixCursor cursor = new MatrixCursor(columns); for(int i = 0; i < items.size(); i++) { temp[0] = i; temp[1] = items.get(i); cursor.addRow(temp); } searchView.setSuggestionsAdapter(newExampleAdapter(MainActivity.this, cursor, items)); } }