private void rewriteQueryFromSuggestion ( int position ) { CharSequence oldQuery = mQueryTextView . getText ( ) ; Cursor c = mSuggestionsAdapter . getCursor ( ) ; if ( c == null ) { return ; } if ( c . moveToPosition ( position ) ) { // Get the new query from the suggestion. CharSequence newQuery = mSuggestionsAdapter . convertToString ( c ) ; if ( newQuery != null ) { // The suggestion rewrites the query. // Update the text field, without getting new suggestions. setQuery ( newQuery ) ; } else { // The suggestion does not rewrite the query, restore the user's query. setQuery ( oldQuery ) ; } } else { // We got a bad position, restore the user's query. setQuery ( oldQuery ) ; } }
Query rewriting .