简体   繁体   中英

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

public 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM