Skip to content

Instantly share code, notes, and snippets.

@v3n3
Last active February 24, 2017 22:52
Show Gist options
  • Select an option

  • Save v3n3/7802bccbb5c4eb0dad17e841a9ca5929 to your computer and use it in GitHub Desktop.

Select an option

Save v3n3/7802bccbb5c4eb0dad17e841a9ca5929 to your computer and use it in GitHub Desktop.
@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