Android: Return search query to current activity

前端 未结 9 1129
半阙折子戏
半阙折子戏 2020-12-07 16:34

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

相关标签:
9条回答
  • 2020-12-07 17:25

    Briefly:

    1. Add android:launchMode="singleTop" to the searchable activity definition in the AndroidManifest.xml
    2. Implement onNewIntent in the searchable activity and handle the search there.
    0 讨论(0)
  • 2020-12-07 17:27

    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.

    0 讨论(0)
  • 2020-12-07 17:30

    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.

    0 讨论(0)
提交回复
热议问题