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

Feature Bug #92

Closed Limuyang1013 closed 8 years ago

Limuyang1013 commented 8 years ago

When I open the search bar when the pop-up search list, if this time I click on the phone's Back button, the first time will close the soft keyboard, but even then a soft keyboard, the default search list will not recover themselves, envision a case, if I do not want to select any one of the list and at the moment I just want to use the return key to exit, the user no matter how pressing the return key will not spring back to the main interface, which is not very good for the user, ask about what can be shut down or drop-down list you can improve it

joydeepsaha05 commented 8 years ago

@GiitSmile Its a bit tough to understand your issue, could you explain what you want to do in steps?

Limuyang1013 commented 8 years ago

I am sorry not expressed clearly,I mean, when i click the floatingsearchview,it will get focus and will pop up a soft keyboard and selection list,But if this time I click on the phone's Back button,The preferred soft keyboard Close,When I pressed a second time the phone's Back button,the Drop-down list does not automatically disappear Unless you choose the item in the list,I think this is not good,I envisioned the user can click on the phone's Back button to remove the focus

joydeepsaha05 commented 8 years ago

@GiitSmile That's easy, just listen to back press events and check if the searchView is in focus or not. Here's a snippet:

@Override
public void onBackPressed() {
    if (searchView.isSearchBarFocused()) {
        searchView.clearSearchFocus()
    } else {
        super.onBackPressed();
    }
}
Limuyang1013 commented 8 years ago

Oh Thank you, I just did'n find this method in the README 发自网易邮箱大师 On 2016-07-22 19:02 , Joydeep Saha Wrote: @GiitSmile That's easy, just listen to back press events and check if the searchView is in focus or not. Here's a snippet: @Override public void onBackPressed() { if (searchView.isSearchBarFocused()) { searchView.clearSearchFocus() } else { super.onBackPressed(); } } — You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or mute the thread.

arimorty commented 8 years ago

Thanks @joydeepsaha05 there is an even easier way to do it as seen in the sample app. if (!mSearchView.setSearchFocused(false)) { super.onBackPressed(); }

nurhadi-ab commented 8 years ago

Hi all, I'm still facing this issue. This code searchView.isSearchBarFocused() always return false, then when I press phone's back button always exit the app.

@Override
public void onBackPressed() {
    if (searchView.isSearchBarFocused()) {
        searchView.clearSearchFocus()
    } else {
        super.onBackPressed(); // always executed
    }
}
arimorty commented 8 years ago

Hi @nurhadi-ab,

There is a new feature in the latest build that allows you to clear focus from the search view automatically when the keyboard is closed. app:floatingSearch_close_search_on_keyboard_dismiss="true" that is probably why you get searchView.isSearchBarFocused() == false since it's already not focused at that point.

Regards,

nurhadi-ab commented 8 years ago

@arimorty thank you, now perfect.