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 668 forks source link

Clear button is not visible after the second focus and writing #78

Closed PetrDana closed 8 years ago

PetrDana commented 8 years ago

Hi, when i focus first and start writing, clear button is displayed. After lost focus (onFocusCleared) I call setSearchText method for keep query string. After second raising focus and writing, clear button is not displayed. I guess it's just that mClearButton member visibility is set to View.GONE in setSearchFocusedInternal(), but in setupQueryBar() and onTextChanged() is View.INVISIBLE used.

Please check this and fix, thank you.

And one more request - show clear button after FloatingSearchView get focus if mSearchInput is not empty, thanks.

fabriciointerama commented 8 years ago

Same here.

Clear query button (right X button) only appear the first time I click and type. If search field lost focus and I click it back, clear button is not there anymore and never come back again.

How to reproduce:

  1. click the search label
  2. type "test". X button should appear.
  3. click on the black background area to remove the focus from it.
  4. click on the search label again. X button is not there anymore.
  5. keep typing something else. X button is not there.

Bonus: should the clear button hide the suggestion list when clicked? Currently it keeps the suggestion list opened. Maybe a flag to set that?

joydeepsaha05 commented 8 years ago

Try doing this when the searchView gains focus:

mSearchView.setOnFocusChangeListener(new FloatingSearchView.OnFocusChangeListener() {
            @Override
            public void onFocus() {
                mSearchView.clearQuery();
                mSearchView.setSearchText("");    //your text here
            }

            @Override
            public void onFocusCleared() {
                //some other magic
            }
});
arimorty commented 8 years ago

@fabriciointerama regarding the bonus you mentioned, you can make use of the onSearchTextChanged listener to implement logic that will do that.