在操作栏搜索插件不会触发我的搜索活动 [英] Search widget on action bar doesn't trigger my search activity

查看:103
本文介绍了在操作栏搜索插件不会触发我的搜索活动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开发的搜索widget界面根据官方教程:<一href="http://developer.android.com/guide/topics/search/search-dialog.html">http://developer.android.com/guide/topics/search/search-dialog.html

I'm developing search widget interface based on official tutorial: http://developer.android.com/guide/topics/search/search-dialog.html

问题:我SearchableActivity当我输入我的查询和preSS确定不会被触发/输入

Problem: My SearchableActivity doesn't get triggered when I enter my query and press Ok/enter.

舱单SearchableActivity:

<activity android:name="SearchableActivity" android:launchMode="singleTop" >
        <intent-filter>
            <action android:name="android.intent.action.SEARCH" />
        </intent-filter>

        <meta-data
            android:name="android.app.searchable"
            android:resource="@xml/searchable" />
</activity>

XML / searchable.xml

<?xml version="1.0" encoding="utf-8"?>
<searchable xmlns:android="http://schemas.android.com/apk/res/android"
android:hint="Search" android:label="@string/app_name" >
</searchable>

主要业务生命周期的方法,该方法将图标添加到动作栏(正常工作):

@Override
public boolean onCreateOptionsMenu(Menu menu) {

    getMenuInflater().inflate(R.menu.main, menu);

    // Get the SearchView and set the searchable configuration
    SearchManager searchManager = (SearchManager)getSystemService(Context.SEARCH_SERVICE);
    SearchView searchView = (SearchView) menu.findItem(R.id.menu_search).getActionView();
    searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));

    // Do not iconify the widget;expand it by default
    searchView.setIconifiedByDefault(false);

    return true;
}

SearchableActivity.java

public class SearchableActivity extends ListActivity {

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Log.d("MY", "search activity triggered");
   }

}

注意:搜索小工具出现在操作栏,我可以插入数据,但pressing确定/输入不带我去SearchableActivity(不触发的onCreate该SearchableActivity)。

Note: The search widget appear on the action bar and I can insert data, but pressing the OK/Enter doesn't take me to the SearchableActivity (doesn't trigger onCreate of the SearchableActivity).

我缺少的东西或者是官方教程有缺陷?

Am I missing something or is the official tutorial flawed?

推荐答案

问题解决了:教程似乎漏掉了一个重要的部分:&LT;元数据的android:NAME =android.app.default_searchable 机器人:值=MySearchActivityName/&GT; &LT内部加入;用途&gt; 标签清单中得到搜索窗口小部件的工作正确的。

Problem solved: the tutorial seems to missing one important part: <meta-data android:name="android.app.default_searchable" android:value=".MySearchActivityName" /> has to be added inside <application> tags in manifest to get the search widget working correctly.

修改 - 兼提示解决问题时,动作条搜索没有在数据发布(任何给定及文件还没有得到关于这个限制词没有错误)引发:在搜索。 xml文件的android:提示和android:标签属性的必须是引用到strings.xml中的字符串。 来源

EDIT- Also a hint to solving a problem when the actionbar search is not triggered on data posting (no error given whatsoever and documentations hasn't got a word about this limitation): in searchable.xml file android:hint and android:label attributes MUST be references to strings in strings.xml. Source

这篇关于在操作栏搜索插件不会触发我的搜索活动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆