Closed sergii-frost closed 9 years ago
Oh hi,
With FakeSearchView.setSearchText(CharSequence)
is possible clear the search view like the snippet:
searchView.setSearchText("");
Prety ughly rsrs but works
@leonardoxh thanks for very quick answer! I am doing right that in case if user interacts with another controls (e.g. with radio buttons in the same fragment - then I am fakeSearchView.setSearchText("")
)
But in case if user inputs something in fake search view, and then he wants to go back with "<--" arrow shown in Action/Toolbar, then fakeSearchView edit text becomes hidden, but not cleared, thus filter for my RecyclerView is not cleared, as expected.
That is why I was wondering, how I can handle this specific action (or same happens when user taps on Back button of phone itself - Fake Search View is becoming hidden, and only my search glass button is shown to activate it again)
UPD: I am attaching .gif as it is easier to understand with it:
So I want "123" be cleared after I click on "<--" :)
Oh yeah,
The FakeSearchView is an action view class in you case ?
OnActionExpandListener
is what you need
Usualy on my codes I use this:
private void prepareSearchView(Menu menu) {
MenuItem menuItem = menu.findItem(R.id.search);
searchView = (FakeSearchView) MenuItemCompat
.getActionView(menuItem);
MenuItemCompat.setOnActionExpandListener(menuItem, this);
searchView.setOnTextChangeListener(this);
}
So, with the onMenuItemActionCollapse
clear the searchview :) and the onMenuItemActionExpand
does nothing
@leonardoxh Yes! You are the man! :100: :+1: Works like a charm! Feel free to close an issue :)
Very nice,
I'll implement a way to do that automatically.
Closing...
Hi, I am happy to start using your custom Search View, it is what I was looking for! I am trying to adjust it a bit so that it worked as user expects it. At current moment I need to clear search text in case if "<--" or back button is used, so that user could see unfiltered results in this case. Can you please tell me if there is any "public" way of ding that in current 0.3.1 version of the library?