开发者

android search dialog not working

I have used given tutorial on the androids guide and done what all is needed still after pressing search button on device or menu item. its doesn't open up the search dialog. I got tutorial from here http://developer.android.com/guide/topics/search/search-dialog.html

I must post my sample codes here so you guys can look into it and help if possible so i can know where I'm going wrong. Activity in which dialog should appear

<activity android:name=".testAndroid"
                  android:theme="@android:style/Theme.NoTitleBar">
                  <meta-data android:name="android.app.default_searchable"
                   android:value="com.tester.android.Search" />
        </activity>

Activity which returns results for search

<activity android:name=".Search" android:label="Search">
            <intent-filter>
                <action android:name="android.intent.action.SEARCH" />
                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
            <meta-data android:name="android.app.searchable" android:resource="@xml/searchable"/>
        </activity>

my searchable file in res/xml folder

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

Activity which shows results

pu开发者_运维知识库blic class Search extends ListActivity {

    private Vector<?> loadedArticles;

    @Override
    protected void onCreate(Bundle icicle) {
        super.onCreate(icicle);

        setContentView(R.layout.articles);
        Intent intent = getIntent();
        String query="";
        if (Intent.ACTION_SEARCH.equals(intent.getAction())) {
            query = intent.getStringExtra(SearchManager.QUERY);
        }

        boolean articlesLoaded = findArticles(query); // it shows results and renders it.

    }
}

Can someone help me please, Why I can't see search dialog after pressing search hardware button.


Finally I myself found the solution to the problem

<searchable xmlns:android="http://schemas.android.com/apk/res/android"
    android:label="XYZ.com"
    android:hint="Search XYZ.com" >
</searchable>

Here I have used lablel and hint as direct string. Instead we need to use, @string/label I mean our string should be in strings.xml and then use them. This is bug in Android.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜