I have a app in which i wish to add search feature, i am trying to implement as told in developer.android
but the activity does not start when i click on search in emulator, what is the problem?
SearchActivity.java
public class SearchActivity extends ListActivity { public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); handleIntent(getIntent()); } @Override public void onNewIntent(Intent intent) { super.onNewIntent(intent); setIntent(intent); handleIntent(intent); } public void onListItemClick(ListView l, View v, int position, long id) { // call detail activity for clicked entry } private void handleIntent(Intent intent) { if (Intent.ACTION_SEARCH.equals(intent.getAction())) { String query =intent.getStringExtra(SearchManager.QUERY); doSearch(query); } } private void doSearch(String queryStr) { // get a Cursor, prepare the ListAdapter // and set it } }
xml/searchable.xml
<?xml version="1.0" encoding="utf-8"?> <searchable xmlns:android="http://schemas.android.com/apk/res/android" android:label="@string/app_name" android:hint="@string/srchHint" android:inputType="textCapCharacters"> </searchable>
AndroidManifest.xml
(code below does not show other activities)<application> <!-- other actvities --> <activity android:label="@string/app_name" android:launchMode="singleTop" android:name=".SearchActivity"> <intent-filter> <action android:name="android.intent.action.SEARCH" /> </intent-filter> <meta-data android:name="android.app.searchable" android:resource="@xml/searchable" /> </activity> </application>
Things already tried:
1. looks at similar question and their solution at StackOverflow
2. Look at tutorials at grokkingandroid and edumobile, they did not help my problem.
3. Spend time asking people at chat.stackoverflow
Problem/Questions
1. Ok i have doSearch()
method, but how exactly fire a query and how to display results from db(take a small db to show example how exactly, if you can), how to populate results.
2. The search activity does not start when i click on search in the emulator.
3. What exactly to keep in mind, while designing search apart from the developer.android
stuff, the other details which many times the site does not tell.
4. How to perform a full-text search, i read about it on developer.android
, how to have my db be good to have a FTS
P.S: I am new to learning android, so if there is a rookie mistake, please bear with it, do not skip over steps.