Custom Offers in Search Widget (Android ICS)

I have an action bar with a search widget in my ICS application. I want the user to be able to search for some of the materials that came with the application. Therefore, I want to use a search widget, displaying a list of results, which is updated when the user enters a new char (the same functionality as the Play Store). I implemented SearchView.OnQueryTextListener in my activity and implemented two methods onQueryTextChange(String newText) and onQueryTextSubmit(String query) . In onQueryTextChange I call my service, which returns values โ€‹โ€‹for a typed sentence. But I have no plan how to display a list of offers. I read developer.android.com articles, but as I understand it, this is mainly for the old search implementation (<Honeycomb). In the examples of the search widget API, the sentences are applications installed on the system, served by SearchManager . I did not find a tutorial or an example that covers this topic (custom suggestions in search widgets), does anyone 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 ContentProvider extend ContentProvider from SearchRecentSuggestionsProvider , but I donโ€™t know how I process and create this provider. I have a searchable.xml called searchSuggestAuthority for my empty content provider. In AnroidManifest, I added a search intent in MainActivity, added metadata, and added my provider. But I donโ€™t know how to get my values โ€‹โ€‹in the Content Provider and display them as offers.

 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

+4
source share

Source: https://habr.com/ru/post/1415975/


All Articles