Last active
May 5, 2016 16:05
-
-
Save IlyaEremin/366b1753c24ed2302ae6 to your computer and use it in GitHub Desktop.
SearchBox back button bugfix
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
thank you that fixed the issue
don't forget
setActivity
is essential