Je suis en train de mettre en place un adaptateur de suggestion de recherche personnalisée (as explained in the documentation) dans mon activité des recherches de la manière suivantesetSuggestionAdapter() ne fonctionne pas avec android.support.v7.widget.SearchView
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.search_result_menu, menu);
SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
SearchView searchView = (SearchView) menu.findItem(R.id.search_result_search_widget).getActionView();
searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
SuggestionCursorAdapter suggestionCursorAdapter = new SuggestionCursorAdapter(this, null);
searchView.setSuggestionsAdapter(suggestionCursorAdapter);
return true;
}
Mon SuggestionCursorAdapter.class ressemble à ceci:
public class SuggestionCursorAdapter extends CursorAdapter {
public SuggestionCursorAdapter(Context context, Cursor c) {
super(context, c, 0);
}
@Override
public View newView(Context context, Cursor cursor, ViewGroup parent) {
return LayoutInflater.from(context).inflate(R.layout.list_item, parent, false);
}
@Override
public void bindView(View view, Context context, Cursor cursor) {
TextView text1 = (TextView) view.findViewById(R.id.list_item_text1);
TextView text2 = (TextView) view.findViewById(R.id.list_item_text2);
String text1String = cursor.getString(cursor.getColumnIndexOrThrow(SearchManager.SUGGEST_COLUMN_TEXT_1));
String text2String = cursor.getString(cursor.getColumnIndexOrThrow(SearchManager.SUGGEST_COLUMN_TEXT_2));
text1.setText(text1String);
text2.setText(text2String);
}
}
ce produit la compilation eRREUR type incompatible suivante:
Error: incompatible types: SuggestionCursorAdapter cannot be converted to CursorAdapter
Je suppose que l'erreur vient de moi en utilisant android.support.v7.widget.SearchView
qui n'est pas supporté par .setSuggestionAdapter()
. Donc je devrais changer en utilisant android.widget.SearchView
que je ne veux pas.
Quelqu'un at-il une idée de comment je peux surmonter cela? Y at-il une alternative à .setSuggestionAdapter()
?
Merci pour vos idées & conseils!
On dirait que vous avez importé la mauvaise classe 'CursorAdapter' importée. Assurez-vous que vous utilisez [le support 'CursorAdapter'] (https://developer.android.com/reference/android/support/v4/widget/CursorAdapter.html) -' import android.support.v4.widget.CursorAdapter ". –
merci, qui a résolu le problème, voulez-vous en faire la réponse à cette question? – Joni