I have an action bar with a search widget in my ICS app. I want that the user can search some stuff which came with the app. Therefore I want to use the search widget, displaying a result list which updates itselfs when the user typ in a new char (same functionality like the Play Store). I have implemented SearchView.OnQueryTextListener
in my activity and implement the two methods onQueryTextChange(String newText)
and onQueryTextSubmit(String query)
. In onQueryTextChange
I call my service, that returns the values for the typed suggestion. But I have no plan, how to display a suggestion list. I read the articles on developer.android.com, but as far as I understand it is mainly for the old search implementation (< Honeycomb). In the Search Widget API Examples the suggestions are apps, installed on the system, served by SearchManager
. I havn't found a tutorial or example which covers this topic (custom suggestions in search widget), does anybody know something like this?
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.search_menu, menu);
SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
SearchView searchView = (SearchView) menu.findItem(R.id.menu_search).getActionView();
searchView.setOnQueryTextListener(this);
return super.onCreateOptionsMenu(menu);
}
@Override
public boolean onQueryTextChange(String newText) {
Log.i(TAG, "Query = " + newText);
if(newText.length() > 0){
//my suggestion service, returning an arraylist!
}
return false;
}
I read, that I need a ContentProvider
extend from SearchRecentSuggestionsProvider
, but I don't know how I handle and create this provider. I have a searchable.xml
which refers as searchSuggestAuthority
to my blank content provider. In the AnroidManifest I added a Search Intent to the MainActivity, add the meta-data and added my provider. But I don't know how to get my values to the Content Provider and display these as suggestions.
public class SuggentionsProvider extends SearchRecentSuggestionsProvider {
public final static String AUTHORITY = "com.sap.hui.helper.SuggentionsProvider";
public final static int MODE = DATABASE_MODE_QUERIES;
public SuggentionsProvider(){
setupSuggestions(AUTHORITY, MODE);
}
}
BR,
mybecks
I believe these are what you need.
The tutorial:
http://developer.android.com/guide/topics/search/adding-custom-suggestions.html
The example:
http://developer.android.com/tools/samples/index.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With