Last active
February 24, 2017 22:52
-
-
Save v3n3/7802bccbb5c4eb0dad17e841a9ca5929 to your computer and use it in GitHub Desktop.
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
| @BindingAdapter("onKeyDone") | |
| public static void onKeyDone(EditText editText, final OnKeyPressedListener action) { | |
| if (editText != null) { | |
| editText.setOnKeyListener(new View.OnKeyListener() { | |
| @Override | |
| public boolean onKey(View v, int keyCode, KeyEvent event) { | |
| boolean handled = false; | |
| if (keyCode == KeyEvent.KEYCODE_ENTER | |
| && event.getAction() == KeyEvent.ACTION_DOWN) { | |
| action.onKeyPressed(); | |
| handled = true; | |
| } | |
| return handled; | |
| } | |
| }); | |
| } | |
| } | |
| public interface OnKeyPressedListener { | |
| void onKeyPressed(); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment