简体   繁体   中英

How to implement a Searchview in android?

I added some code to oncreate options menu like this

 SearchManager searchManager =
           (SearchManager) getSystemService(Context.SEARCH_SERVICE);
    SearchView searchView =
            (SearchView) menu.findItem(R.id.search).getActionView();
    searchView.setSearchableInfo(
            searchManager.getSearchableInfo(getComponentName()));

Also I created a xml file in xml directory and I did what is said in this .But I don't know how to pass search query and get the result. Executing this getting action bar disappeared.

Furthermore if you want have some callback use the code below, on putting some query and fetch it.

searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
        @Override
        public boolean onQueryTextSubmit(String query) {

            return false;
        }

        @Override
        public boolean onQueryTextChange(String s) {
            return false;
        }
    });

Android Search View Example in android Working Source Code

https://drive.google.com/open?id=0BzBKpZ4nzNzUajJhNEV2N25qWlU

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM