0

Hi all,

I have a activity which have a listview. I need to refine the listview by people's inputs.

I have tried to implement it by following the topic http://developer.android.com/guide/topics/search/search-dialog.html. but the problem is that I can only get the default searchbar (which can search contacts or any words in browser) from system after press the search button.

So my question is how to implement a search locally?

Thank you in advance.


In the searchable activity ListActivity:

@Override
public boolean onSearchRequested(){
    Bundle bundle=new Bundle();
    bundle.putString("data", "data");
    startSearch(null, false, bundle, false);
    return true;
}

In the manifest:

<searchable xmlns:android="http://schemas.android.com/apk/res/android"
android:label="DiseaseListActivity"
android:hint="Search Diseases..." 
android:searchMode="showSearchLabelAsBadge"
android:voiceSearchMode="showVoiceSearchButton|launchRecognizer"
android:voiceLanguageModel="free_form"
android:voicePromptText="Please Speak"

/>

The searchable.xml:

<searchable xmlns:android="http://schemas.android.com/apk/res/android"
android:label="DiseaseListActivity"
android:hint="Search Diseases..." 
android:searchMode="showSearchLabelAsBadge"
android:voiceSearchMode="showVoiceSearchButton|launchRecognizer"
android:voiceLanguageModel="free_form"
android:voicePromptText="Please Speak"/>
ThinkChris
  • 1,169
  • 2
  • 15
  • 38

1 Answers1

1

Problem solved, in searchable.xml, we cannot use static string, instead, we should use reference like

android:label="@string/app_name"

Thank you all.

Chris

ThinkChris
  • 1,169
  • 2
  • 15
  • 38