Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 823
Umakant Patil Avatar asked Dec 17 '22 10:12

Umakant Patil


1 Answers

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.

like image 119
Umakant Patil Avatar answered Jan 10 '23 18:01

Umakant Patil