android - Action bar search reset using back button -


i have action bar search menu. when clicked on search icon, focused , soft keyboard shown. want reset search using onbackpressed event. when firstly press button , soft keyboard hide . again press button, search view reset , collapsed.

i have tried in such way failed

@override     public void onbackpressed() {         // it's expensive, if running turn off.        // datahelper.cancelsearch();         hidekeyboard();         super.onbackpressed();     }     private void hidekeyboard() {         inputmethodmanager imm = (inputmethodmanager)              getsystemservice(context.input_method_service);         imm.hidesoftinputfromwindow(msearchview.getwindowtoken(), 0);     } 

my code hide keyboard when press again button navigates previous intent.

stop calling super method not nevigate previous activity soft key board hide.

    @override     public void onbackpressed() {         // it's expensive, if running turn off.        // datahelper.cancelsearch();         hidekeyboard();         //super.onbackpressed();     } 

now can whatever want.


Comments