How do you make the outgoing search list in SearchView?



  • How do you make a falling list of search viriates? SearchView?

    That's the kind of guy who started introducing something, the search options.

    выпадающий список в SearchView



  • Hearers

    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;
                    }
                });
    

    By this method, a fascinating list can be identified. When we want to add or delete the data, we add and remove them in the listeners, but we 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 &gt;= 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 &lt; items.size(); i++) {
    
                temp[0] = i;
                temp[1] = items.get(i);
    
                        cursor.addRow(temp);
            }
    
    
            searchView.setSuggestionsAdapter(newExampleAdapter(MainActivity.this, cursor, items));
    
        }
    
    }
    


Log in to reply
 


Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2