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

After click search button, attr "showSearchKey" back to "false" #62

Closed VuHongKy closed 8 years ago

VuHongKy commented 8 years ago

Hi guy, I set "showSearchKey" attr = "true". But it only effects on first typing, but when I clicked search action button, seem it back to "false". Because I found that when I focus on edit-text, current typing text was not shown and back to empty. Why not? I want to set showSearchKey attr always effect. Why can I do that? Please help.

TheRishka commented 8 years ago

Same with cross that erases text

arimorty commented 8 years ago

Hi, @VuHongKy, @TheRishka

To clarify, the "showSearchKey" attribute is for setting if you want to see the search button in the SoftKeyboard or not, it has nothing to do with the EditText clearing the text. Now, the query should indeed stay in the search bar when the search gains focus, but there is a minor bug that causes it to reset.

A temporary workaround would be to use https://github.com/arimorty/floatingsearchview/blob/master/library/src/main/java/com/arlib/floatingsearchview/FloatingSearchView.java#L1114 when the focus clears, like this:

 mSearchView.setOnFocusChangeListener(new FloatingSearchView.OnFocusChangeListener() {
            @Override
            public void onFocus() {
                //grab the query mSearchView.getQuery() and swapSuggestions accordingly
           }

            @Override
            public void onFocusCleared() {
                mSearchView.setSearchText(mSearchView.getQuery());
            }
        });
VuHongKy commented 8 years ago

Thanks, @arimorty I tried to setOnFocusChangeListener() before, but I don't know how to set search query. Thanks for your guide. I'm trying now.

VuHongKy commented 8 years ago

Hi @arimorty I set query when focus search bar, but in that case, query != null, but clear button doesn't show. ??? What can i do now? Thanks.

arimorty commented 8 years ago

@VuHongKy a fix for "but clear button doesn't show" which is also mentioned in #91 is in develop and will be part of the next release.

Thanks,