I'm currently trying to implement a Search in my App. I followed Google's Tutorial but now, when i press the "Search"-Button (on the Device/Emulator), nothing appears. I'm not sure why.
My searchable.xml File:
<?xml version="1.0" encoding="utf-8"?>
<searchable
xmlns:android="http://schemas.android.com/apk/res/android"
android:label="@string/label_search"
android:hint="@string/search_hint"
android:includeInGlobalSearch="true"
>
</searchable>
This is the Android Manifest part for the Search-Activity:
<!-- Search Activity -->
<activity android:name=".SearchNotes">
<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>
The Code which populates my ListActivity:
private void searchAndDisplay(String query){
SQLiteDatabase db = db_con.getReadableDatabase();
final Cursor c = db.rawQuery(
"SELECT headline, id as '_id' FROM entry WHERE " +
"(headline LIKE '%?%') OR (content LIKE '%?%') ",
new String[]{query, query});
this.startManagingCursor(c);
final ListAdapter searchAdapter = new SimpleCursorAdapter(
this,
android.R.layout.simple_list_item_2, c,
new String[] {"headline", "_id"},
new int[] {android.R.id.text1, android.R.id.text2});
this.setListAdapter(searchAdapter);
db.close();
}
This doesn't work in the Emulator, neither on my Android-Device. What am I missing here?
Do you have
<activity android:name=".OtherActivity" ... >
<!-- enable the search dialog to send searches to SearchableActivity -->
<meta-data android:name="android.app.default_searchable"
android:value=".SearchNotes" />
</activity>
inside your Activity tag? It can also be applied to the Application if you so choose.