Pass ActionBar search query to fragment

Viewed 8051

Here is the seen I have a SHERLOCK FRAGMENT ACTIVITY which holds four FRAGMENTS and a SEARCH VIEW. There are 4 fragments in which last is FRAGMENT SEARCH RESULTS

My question is how to pass data of search query to FRAGMENT SEARCH RESULTS from search view and display search result in FRAGMENT SEARCH RESULTS

I implemented this

private void setupSearchView(MenuItem searchItem) {
        if (isAlwaysExpanded()) {
            mSearchView.setIconifiedByDefault(false);
        } else {
            searchItem.setShowAsActionFlags(MenuItem.SHOW_AS_ACTION_IF_ROOM | MenuItem.SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW);
        }
        mSearchView.setOnQueryTextListener(this);
    }

    public boolean onClose() {
        return false;
    }

    protected boolean isAlwaysExpanded() {
        return false;
    }

    @Override
    public boolean onQueryTextSubmit(String query) {
        if (query.length() > 0) {
            **//WHAT SHOULD I WRITE HERE**
        }
        return false;
    }

    @Override
    public boolean onQueryTextChange(String newText) {
        return false;
    }
3 Answers

A good example in here action-bar-search-view.

To display search result, you need to pass submitYourQuery(query); and return true on successful search.

The process of storing and searching your data is unique to your application. You can store and search your data in many ways. Storing and searching your data is something you should carefully consider in terms of your needs and your data format.

Get the more details from the android documentation ReceivingTheQuery

Related