1

I have seen those links below. But, still my getSearchableInfo returns null and cannot kick search. I user search widget. So, search execution and getting result are done on the same Activity.

I am using onQueryTextSubmit instead currently. But, I can not set text at SearchView and parameter for query string passed from another Activity is missed. This is annoying.

Android: getSearchableInfo(getComponentName()) returning null? searchManager.getSearchableInfo(getComponentName()) returns null

I upload class and xmls.

res/xml/searchable.xml:

<?xml version="1.0" encoding="utf-8"?>

<searchable xmlns:android="http://schemas.android.com/apk/res/android"
    android:hint="@string/search_condition"
    android:label="@string/search_label"
    android:searchSuggestAuthority="company_crediation"
    android:searchSuggestIntentAction="android.intent.action.VIEW"
    android:searchSuggestSelection=" ? ">
</searchable>

Manifext.xml CompanySearchActivity has searchview and this Activity will be started by a fragment on HomeActivity.

<application
    android:allowBackup="true"
    android:icon="@drawable/icon"
    android:label="@string/app_name"
    android:roundIcon="@drawable/icon"
    android:supportsRtl="true">
    <activity android:name=".NoDisplayActivity"
        android:theme="@style/CcAppTheme">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity
        android:name=".HomeActivity"
        android:label="@string/app_name"
        android:theme="@style/CcAppTheme"></activity>
    <activity
        android:name=".CompanySearchActivity"
        android:launchMode="singleTop"
        android:label=""
        android:theme="@style/CcAppThemeSearch">
        <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"/>
        <meta-data
            android:name="android.app.default_searchable"
            android:value=".CompanySearchActivity" />
    </activity>
</application>

CompanySearchActivity.java As written before, OnQueryTextListener I am using it because I am getting this issue.

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

    SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
    SearchView searchView = (SearchView)menu.findItem(R.id.company_search).getActionView();
    SearchableInfo searchableInfo = searchManager.getSearchableInfo(getComponentName());
    searchView.setSearchableInfo(searchableInfo);
    searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
        @Override
        public boolean onQueryTextSubmit(String query) {
            doSearchWithQuery(query);
            return false;
        }

        @Override
        public boolean onQueryTextChange(String newText) {
            return false;
        }
    });
    searchView.setIconified(false);
    searchView.setSubmitButtonEnabled(false);

    return true;
}

I hope someone helps me.

0 Answers0