android searchable不起作用 [英] android searchable doesn't work

查看:98
本文介绍了android searchable不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用可搜索的操作栏.我有一个问题,就是操作栏不会对可搜索活动做出反应.就是说,我在操作栏的可搜索textedit中输入了一些内容,然后单击了提交,但是什么也没有发生.调试跟踪显示,我的searchresultactivity中的代码从未执行过.因此,我想知道可搜索配置中是否存在错误.好吧,这次我想我已经清楚地解释了这个问题,并且我希望没有任何口头吐出任何否定票!

I'm working around with a searchable action bar. And I gotta a problem that the action bar doesn't react with the searchable activity. THAT IS, I enter something in the action bar's searchable textedit then clicked the submit but nothing happened. The debug tracking shows that the code in my searchresultactivity is never executed. So I'm wondering if there's something wrong in searchable configuration. Well this time I think I've explained the problem clearly and I don't expect any negative votes without any words even spits!

我遵循manifest.xml开头的开发人员文档说明,将元数据添加到searchresult活动中:

I followed the instruction of developer's document beginning with the manifest.xml, the meta-data is added in the searchresult activity:

<application
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name" >
    <activity
        android:name=".GermanDictionaryActivity"
        android:label="@string/app_name">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity android:name=".SearchResultsActivity">
        <intent-filter>
            <action android:name="android.intent.action.SEARCH" />
        </intent-filter> 
        <meta-data android:name="android.app.searchable"
            android:resource="@xml/searchable" />
    </activity>
</application>

然后我用菜单初始化了搜索视图:

then I initialized the searchview with my menu:

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.srhbar, menu);

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

    return true;
}

以及菜单中的可搜索项目:

And the searchable item in menu:

<item android:id="@+id/search"
    android:title="@string/srh_title"
    android:showAsAction="collapseActionView|ifRoom"
    android:actionViewClass="android.widget.SearchView" />

任何与之相关的答案都将受到赞赏!

Any answer related is appreciated!

推荐答案

我通过更改以下行来解决了这个问题:

I solved the problem by changing this line:

searchView.setSearchableInfo(searchManager.getSearchableInfo(new ComponentName(getApplicationContext(), SearchResultsActivity.class)));

这篇关于android searchable不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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