Skip to content Skip to sidebar Skip to footer

Android Searchable Not Opening

Hi im trying to use a searchable activity in my application but when the search button is pressed nothing happens AndroidManifest.xml

Solution 1:

Your Searchable activity has to do something - and actually display results.

I just wrote one as suggested by an answer to a question I asked yesterday Trying to filter a ListView with runQueryOnBackgroundThread but nothing happens - what am I missing?

Look at this documentation for how to integrate with the built in search support: Using the Android Search Dialog and look at this article on how to offer suggestions as the customer types: Adding Custom Suggestions

Your class Searchable needs to do a bit more after getting the query string. For example in my activity after getting the query string I do this:

showResults(query);

and that method looks like this:

privatevoidshowResults(String query)  {
    //  Load the list of countries based on the queryCursorcountryCursor= myDbHelper.getCountryList (query);
    startManagingCursor (countryCursor);

    //  Hook up the query results to the list view
    String[] from = newString[]  {
        WorldInfoDatabaseAdapter.KEY_COUNTRYCODE, WorldInfoDatabaseAdapter.KEY_COUNTRYNAME
    };
    int[] to = newint[]  {
        R.id.countryflag, R.id.countryname
    };
    SimpleCursorAdapteradapter=newSimpleCursorAdapter (this,
            R.layout.country_list_row, countryCursor, from, to);
    adapter.setViewBinder (newFlagViewBinder ());

    myCountryList.setAdapter (adapter);
    myCountryList.setOnItemClickListener (newOnItemClickListener () {

        @OverridepublicvoidonItemClick(AdapterView<?> parent, View view, int position, long id) {
            StringcountryName= myDbHelper.getCountryByID (id);
            if (countryName == null)  {
                newAlertDialog.Builder (SelectCountryActivity.this).setMessage (
                        "Internal error: Cannot find the country with id'" + id + "'.").show ();

                return;
            }

            //  Package up the country name to returnIntentnewCountryIntent=newIntent (myCountryList.getContext (), WorldInfoActivity.class);
            newCountryIntent.putExtra (WorldInfoActivity.KEY_SELECTED_COUNTRY, countryName);
            startActivity (newCountryIntent);

            startActivity (newCountryIntent);
            finish ();
        }
    });
}

The member myDbHelper queries my database for countries that have the passed in query string and displays them in a list. My activity has a layout that looks like this:

<?xml version="1.0" encoding="utf-8"?><LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android"android:layout_width="fill_parent"android:layout_height="fill_parent"android:orientation="vertical"style="?pageBackground"><TextViewandroid:id="@+id/selectdlgtitle"android:layout_width="fill_parent"android:layout_height="wrap_content"android:text="@string/select_country_title"style="?dlgTitle" /><ListViewandroid:id="@+id/countrylist"android:layout_width="fill_parent"android:layout_height="fill_parent"android:cacheColorHint="#00000000"android:padding="2px"/></LinearLayout>

You can probably do without the setViewBinder call - I need that because I am translating the country code field into a flag icon.

Post a Comment for "Android Searchable Not Opening"