3

i already get the search suggestion while typing in the searchfield of the search-dialog. While typing in Portrait-Mode, the result are listed under the search-dialog. But when i change into landscape-mode, the text-input-field of the searchdialog becomes fullscreen (i hope you know what i mean) and the search suggestions couldn't be see anymore. i know for example from google maps that also in landscape mode the search suggestions are show under the "big" text-input-field...Wich code should i type to get this "view" while typing in landscape-mode?

Thanks!

Thomas

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
Tschakle
  • 225
  • 1
  • 4
  • 14

1 Answers1

5

If you want your suggestions to show up in landscape, you need to do one of the following:

  • Add SUGGEST_COLUMN_QUERY to your suggestion results
  • Add android:searchMode="queryRewriteFromText" or ``android:searchMode="queryRewriteFromData"to yoursearchable.xml`

However, I think for suggestions it's nicer to just show the normal popup instead of a fullscreen keyboard. You can achieve this by adding android:imeOptions="flagNoExtractUi" to your searchable.xml.

And that's all. If you're curious, here's how I tracked this down:

Hierarchy Viewer will tell you that the search dialog is implemented by SearchDialog, which uses an AutoCompleteTextView for the completion text view. Its buildDropDown() function calls Filter.convertResultToString() (through convertSelectionToString()) on the items returned by the AutoCompleteTextView's mAdapter.getItem() and then passes these on to InputMethodManager.displayCompletions() (which is responsible for the suggestions you want).

In the case of SearchDialog, the adapter is a SuggestionsAdapter. This is a subclass of CursorAdapter, whose getFilter() method returns a CursorFilter class, which implements convertResultToString() by just delegating to convertToString() on the adapter class. SuggestionsAdapter finally implements this method as follows:

public CharSequence convertToString(Cursor cursor) {
    if (cursor == null) {
        return null;
    }

    String query = getColumnString(cursor, SearchManager.SUGGEST_COLUMN_QUERY);
    if (query != null) {
        return query;
    }

    if (mSearchable.shouldRewriteQueryFromData()) {
        String data = getColumnString(cursor, SearchManager.SUGGEST_COLUMN_INTENT_DATA);
        if (data != null) {
            return data;
        }
    }

    if (mSearchable.shouldRewriteQueryFromText()) {
        String text1 = getColumnString(cursor, SearchManager.SUGGEST_COLUMN_TEXT_1);
        if (text1 != null) {
            return text1;
        }
    }

    return null;
}

…which results in the recommendations in the first paragraph above.

thakis
  • 5,405
  • 1
  • 33
  • 33