Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Custom Suggestions in Search Widget (Android ICS)

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

like image 594
mybecks Avatar asked Oct 07 '22 15:10

mybecks


1 Answers

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

like image 154
Jason Tian Avatar answered Oct 12 '22 11:10

Jason Tian