【问题标题】:Custom Suggestions in Search Widget (Android ICS)搜索小部件中的自定义建议 (Android ICS)
【发布时间】:2012-06-04 14:55:58
【问题描述】:

我的 ICS 应用中有一个带有搜索小部件的操作栏。我希望用户可以搜索应用程序附带的一些东西。因此,我想使用搜索小部件,显示一个结果列表,当用户输入新字符时会更新自身(与 Play 商店相同的功能)。我在我的活动中实现了SearchView.OnQueryTextListener,并实现了onQueryTextChange(String newText)onQueryTextSubmit(String query)这两种方法。在onQueryTextChange 中,我调用我的服务,它返回输入建议的值。但我没有计划,如何显示建议列表。我阅读了developer.android.com 上的文章,但据我了解主要是针对旧的搜索实现(SearchManager 提供服务。我还没有找到涵盖该主题的教程或示例(搜索小部件中的自定义建议),有人知道这样的事情吗?

@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;
    }

我读到,我需要从 SearchRecentSuggestionsProvider 扩展的 ContentProvider,但我不知道如何处理和创建此提供程序。我有一个searchable.xml,它指的是searchSuggestAuthority,我的空白内容提供者。在 AnroidManifest 中,我向 MainActivity 添加了一个 Search Intent,添加了元数据并添加了我的提供程序。但我不知道如何将我的值提供给 Content Provider 并将这些值显示为建议。

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,

我的贝克

【问题讨论】:

  • 你找到解决方案了吗?如果是,请分享我

标签: android search android-4.0-ice-cream-sandwich android-actionbar


【解决方案1】:

【讨论】:

  • 自 I/O 以来,谷歌似乎已经更新了整个开发者部分。所以我会尝试再次进入它。 :)
  • 第一个链接详细描述。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2016-04-20
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多