Example usage for android.widget SearchView setSuggestionsAdapter

List of usage examples for android.widget SearchView setSuggestionsAdapter

Introduction

In this page you can find the example usage for android.widget SearchView setSuggestionsAdapter.

Prototype

public void setSuggestionsAdapter(CursorAdapter adapter) 

Source Link

Document

You can set a custom adapter if you wish.

Usage

From source file:com.peaceworld.wikisms.view.newui.BaseActivity.java

@TargetApi(Build.VERSION_CODES.HONEYCOMB)
private void loadData(String query) {

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {

        // Load data from list to cursor
        String[] columns = new String[] { "_id", "text", "cid" };
        Object[] temp = new Object[] { 0, "name", -1l };

        MatrixCursor cursor = new MatrixCursor(columns);

        int index = 0;
        for (int i = 0; i < items.size(); i++) {
            if (query == null || items.get(i).getName().contains(query.trim())) {
                temp[0] = index;/*from www .  ja  v a 2s  . c  o  m*/
                temp[1] = items.get(i).getName();
                temp[2] = items.get(i).getId();
                cursor.addRow(temp);
                index++;
            }
        }

        temp[0] = index;
        temp[1] = "     " + " \"" + query + "\" ";
        temp[2] = query.trim();
        cursor.addRow(temp);

        SearchManager manager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);

        final SearchView search = (SearchView) menu.findItem(R.id.menu_search).getActionView();

        search.setSearchableInfo(manager.getSearchableInfo(getComponentName()));
        ActionBarSearchAdapter adapter = new ActionBarSearchAdapter(this, cursor, this, search);
        search.setSuggestionsAdapter(adapter);

    }

}