Hello.
I would like to implement SearchView with a drop-down list, something like this is done on GooglePlay:
I have an adapter written following the example from this article: http://habrahabr.ru/post/260045/
those. I need to pass the query text to the searchAnker method which will return the cursor.
SearchAnker code:
public Cursor searchAnker(String inputText) throws SQLException { inputText = inputText.toLowerCase(); String query = "SELECT docid as _id," + KEY_INPUT + "," + KEY_ANKER + " FROM " + FTS_VIRTUAL_TABLE + " WHERE " + KEY_INPUT + " MATCH '" + inputText + "';"; Cursor mCursor = mDb.rawQuery(query, null); if (mCursor != null) { mCursor.moveToFirst(); } return mCursor; } SearchView is currently implemented using android.support.v7.widget.SearchView
Here is the xml code:
<item android:id="@+id/action_search" android:title="@string/app_name" android:icon="@mipmap/ic_search_white_24dp" sabd:showAsAction="ifRoom|collapseActionView" sabd:actionViewClass="android.support.v7.widget.SearchView" /> Java code:
... public boolean onCreateOptionsMenu(Menu menu) { if (!mNavigationDrawerFragment.isDrawerOpen()) { // Only show items in the action bar relevant to this screen // if the drawer is not showing. Otherwise, let the drawer // decide what to show in the action bar. getMenuInflater().inflate(R.menu.main, menu); restoreActionBar(); MenuItem searchItem = menu.findItem(R.id.action_search); searchView = (SearchView) MenuItemCompat.getActionView(searchItem); searchView.setQueryHint("Поиск"); searchView.setOnQueryTextListener(this); try { cursor = searchDbAdapter.searchAnker(searchView.getQuery().toString()); } catch (SQLException e) { e.printStackTrace(); } String[] from = new String[]{SearchDbAdapter.KEY_INPUT}; int[] to = new int[]{R.id.search_query_text}; cursorAdapter = new SimpleCursorAdapter(this, R.layout.search_item, cursor, from, to, 0); searchView.setSuggestionsAdapter(cursorAdapter); return true; } return super.onCreateOptionsMenu(menu); } ... @Override public boolean onQueryTextSubmit(String s){ return false; } @Override public boolean onQueryTextChange(String s) { cursorAdapter.changeCursor(cursor); return false; } ... How can such a search be implemented using this searchView? Maybe there are some examples?
Thank.
