Your Searchable activity must do something - and actually show results.
I just wrote one of them, as suggested by the answer to the question I asked yesterday Attempting to filter the ListView using runQueryOnBackgroundThread, but nothing happens - what am I missing?
Take a look at this documentation on how to integrate with the built-in search support: Using the Android Search Dialog and look at this article on how to offer offers as client types: Adding custom offers
Your Searchable class should do a little more after getting the query string. For example, in my activity, after receiving a query string, I do this:
showResults(query);
and this method is as follows:
private void showResults(String query) { // Load the list of countries based on the query Cursor countryCursor = myDbHelper.getCountryList (query); startManagingCursor (countryCursor); // Hook up the query results to the list view String[] from = new String[] { WorldInfoDatabaseAdapter.KEY_COUNTRYCODE, WorldInfoDatabaseAdapter.KEY_COUNTRYNAME }; int[] to = new int[] { R.id.countryflag, R.id.countryname }; SimpleCursorAdapter adapter = new SimpleCursorAdapter (this, R.layout.country_list_row, countryCursor, from, to); adapter.setViewBinder (new FlagViewBinder ()); myCountryList.setAdapter (adapter); myCountryList.setOnItemClickListener (new OnItemClickListener () { @Override public void onItemClick (AdapterView<?> parent, View view, int position, long id) { String countryName = myDbHelper.getCountryByID (id); if (countryName == null) { new AlertDialog.Builder (SelectCountryActivity.this).setMessage ( "Internal error: Cannot find the country with id'" + id + "'.").show (); return; } // Package up the country name to return Intent newCountryIntent = new Intent (myCountryList.getContext (), WorldInfoActivity.class); newCountryIntent.putExtra (WorldInfoActivity.KEY_SELECTED_COUNTRY, countryName); startActivity (newCountryIntent); startActivity (newCountryIntent); finish (); } }); }
The myDbHelper element queries my database for countries that have passed the query string and displays them in a list. My activity has a layout that looks like this:
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" style="?pageBackground"> <TextView android:id="@+id/selectdlgtitle" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/select_country_title" style="?dlgTitle" /> <ListView android:id="@+id/countrylist" android:layout_width="fill_parent" android:layout_height="fill_parent" android:cacheColorHint="#00000000" android:padding="2px"/> </LinearLayout>
Perhaps you can do without calling setViewBinder - I need this because I translated the country code field into a flag icon.
Ian leslie
source share