Sugerencias de búsqueda de Android: sugerencias que no se muestran al escribir en SearchView
Tengo un widget de búsqueda que funciona y quiero agregar sugerencias de historial de búsqueda. Seguí el tutorial de Android (http://developer.android.com/guide/topics/search/adding-recent-query-suggestions.html), y mientras la búsqueda aún funciona, no se muestran sugerencias. Aquí está mi código:
Proveedor de contenido
package com.mypackage;
import android.content.SearchRecentSuggestionsProvider;
public class SearchHistoryProvider extends SearchRecentSuggestionsProvider {
public final static String AUTHORITY = SearchHistoryProvider.class.getName();
public final static int MODE = DATABASE_MODE_QUERIES;
public SearchHistoryProvider() {
setupSuggestions(AUTHORITY, MODE);
}
}
Proveedor declarante en Manifiesto
<provider
android:name=".SearchHistoryProvider"
android:authorities="com.mypackage.SearchHistoryProvider">
</provider>
Configuración de búsqueda
<?xml version="1.0" encoding="utf-8"?>
<searchable xmlns:android="http://schemas.android.com/apk/res/android"
android:label="@string/app_name"
android:hint="@string/search_hint"
android:voiceSearchMode="showVoiceSearchButton|launchRecognizer"
android:searchSuggestAuthority="com.mypackage.SearchHistoryProvider"
android:searchSuggestSelection=" ?">
</searchable>
Guardar las consultas en el proveedor de contenido (en mi actividad de búsqueda)
private void handleIntent(Intent intent) {
if (Intent.ACTION_SEARCH.equals(intent.getAction())) {
String query = intent.getStringExtra(SearchManager.QUERY);
SearchRecentSuggestions suggestions = new SearchRecentSuggestions(this,
SearchHistoryProvider.AUTHORITY, SearchHistoryProvider.MODE);
suggestions.saveRecentQuery(query, null);
// Collapse the search view as a search is performed
MenuItem searchItem = mMenu.findItem(R.id.search);
SearchView searchView = (SearchView) mMenu.findItem(R.id.search).getActionView();
searchItem.collapseActionView();
searchView.setQuery("", false);
// send the query to the global search activity for loading the data
Intent globalSearchIntent = new Intent(this, GlobalSearchFragmentActivity.class);
GroceryOTGUtils.copyIntentData(intent, globalSearchIntent);
globalSearchIntent.putExtra(GlobalSearchFragmentActivity.GLOBAL_SEARCH, true);
startActivity(globalSearchIntent);
}
}
Todo funciona bien, excepto que las sugerencias no se muestran (la búsqueda se ve igual que antes de agregarlas). Cualquier ayuda sería muy apreciada!