Skip to content

Instantly share code, notes, and snippets.

@IlyaEremin
Last active May 5, 2016 16:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save IlyaEremin/366b1753c24ed2302ae6 to your computer and use it in GitHub Desktop.
Save IlyaEremin/366b1753c24ed2302ae6 to your computer and use it in GitHub Desktop.
SearchBox back button bugfix
import android.app.Activity;
import android.content.Context;
import android.util.AttributeSet;
import android.view.KeyEvent;
import android.view.View;
import com.quinny898.library.persistentsearch.SearchBox;
/**
* Created by Ilya Eremin on 11/18/15.
*/
public class MySearchBox extends SearchBox {
private Activity activity;
public void setActivity(Activity activity){
this.activity = activity;
}
public MySearchBox(Context context) {
super(context);
}
public MySearchBox(Context context, AttributeSet attrs) {
super(context, attrs);
}
public boolean dispatchKeyEvent(KeyEvent e) {
if (e.getKeyCode() == KeyEvent.KEYCODE_BACK && this.getVisibility() == View.VISIBLE) {
this.hideCircularly(activity);
return true;
} else {
return super.dispatchKeyEvent(e);
}
}
}
@BMomani
Copy link

BMomani commented May 5, 2016

thank you that fixed the issue

mSearchBox = (MySearchBox) findViewById(R.id.search_box);
mSearchBox.setActivity(this);

don't forget setActivityis essential

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment