arimorty / floatingsearchview

A search view that implements a floating search bar also known as persistent search
https://github.com/arimorty/floatingsearchview/blob/master/README.md
Apache License 2.0
3.54k stars 667 forks source link

Can I get query string when call OnSearchListener.onSearchAction() #15

Closed yangli1120 closed 8 years ago

yangli1120 commented 8 years ago

Hi, I see this code: mSearchInput.setOnKeyListener(new OnKeyListener() {

        public boolean onKey(View view, int keyCode, KeyEvent keyEvent) {

            if (mShowSearchKey && keyCode == KeyEvent.KEYCODE_ENTER) {

                setSearchFocusedInternal(false);

                if (mSearchListener != null)
                    mSearchListener.onSearchAction();

                return true;
            }
            return false;
        }
    });

the EditText will clear text at "setSearchFocusedInternal(false);", and I can't get the query string at onSearchAction(), because I want toggle a search action when user click the search action key at keyboard :(

ayaseruri commented 8 years ago

look at https://github.com/ayaseruri/floatingsearchview

I changed :

void onSearchAction() ==> onSearchAction(String query)

void onFocus() ==> onFocus(String query)

those can help you to handle search event better;

i also add 'floatingSearch_setQueryAsTitle' attributable, the search edittext will not clean the edittext while search if you set the attributable 'true';

arimorty commented 8 years ago

@YoungLeeForeverBoy You can make use of the following to achieve what you want:

First, keep track of your current text in your code and then use the methods below. mSearchView.setSearchBarTitle() - to set the text in the input, but the text will clear once the search gains focus mSearchView.setSearchText(); - to set the text in the input, and the text will NOT clear once the search gains focus

yangli1120 commented 8 years ago

thank you:)

Ivolian commented 8 years ago

@ayaseruri Your idea works, thanks.