I followed the steps described on http://developer.android.com/guide/topics/search/search-dialog.html to implement a search feature in my notepad application.
My pro
Briefly:
android:launchMode="singleTop"
to the searchable activity
definition in the AndroidManifest.xml
onNewIntent
in the searchable activity
and handle the search there.Just add
<application>
<meta-data
android:name="android.app.default_searchable"
android:value="#Activity_Name" />
<!-- All your activities, service, etc. -->
</application>
in your android_manifest.xml file where #Activity_Name is the name of the activity that handles the search.
I simply use this:-
searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
@Override
public boolean onQueryTextSubmit(String s) {
//on submit
return false;
}
@Override
public boolean onQueryTextChange(String s) {
//get all text changes
return false;
}
});
This is best used when you have to search across a listview and have to filter out items. I never go by implementing the search function using the manifest file. The 2 methods do all the job.