Skip to content Skip to sidebar Skip to footer

Search In Android

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 i

Solution 1:

So the Search is crucial factor on how usable your application actually is and provide necessary user enhancement

1. This is one of the most easiest way to handle search

privatevoidhandleIntent(Intent intent) { 
      if (Intent.ACTION_SEARCH.equals(intent.getAction())) { 
         String query = 
               intent.getStringExtra(SearchManager.QUERY); 
         doSearch(query); 
      } 
   }    

   privatevoiddoSearch(String queryStr) 
       { 
       // get a Cursor/ArrayList, prepare the ListAdapter// and set it//helper.getSearchRecords(queryStr);//helper is a SQLiteOpenHelper Object//set it to adapter or get return result and proceed as you wish//personally i prefer ArrayAdapterListView lstResult=(ListView)findViewById(R.id.lstVwResult);
       lstResult.setAdapter(null);
    SearchAdapter adapter=newSearchAdapter(getApplicationContext(), R.id.txvPersonId, helper.getSearchRecords(queryStr));
        lstResult.setAdapter(adapter);
   } 

2. The reason for SearchActivity not starting is <meta-data> need to be define outside the activity also, like this

<application><activityandroid:label="@string/app_name"android:launchMode="singleTop"android:name=".SearchActivity">
            <intent-filter>
                <actionandroid:name="android.intent.action.SEARCH" /></intent-filter>
            <meta-dataandroid:name="android.app.searchable"android:resource="@xml/searchable" /></activity><!--define metadata outside activity in application tag--><meta-dataandroid:name="android.app.default_searchable"android:value=".SearchActivity" />

3. One of the key things to keep in mind, why your are adding search feature to your app, it its a Contacts App, clicking on retrieve results would show more detail to particular contact, but for a restaurant app it will show detail for where restaurant details, you as developer should develop it to crater user needs and enhance user experience.

4. For having Full-Text Search, it is not always necessary, it solely depends on how you wish to query for results to db, which fields will you consider and how are they relevant to main purpose of your application,

For more Reference

Post a Comment for "Search In Android"