Created
August 6, 2015 00:40
-
-
Save jaywick/e005a2dbe1327258d7aa to your computer and use it in GitHub Desktop.
Android - Listen to Enter key down event on a View such as an EditText
This file contains 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
package io.jaywick.android.helpers; | |
import android.view.KeyEvent; | |
import android.view.View; | |
public abstract class OnEnterKeyListener implements View.OnKeyListener | |
{ | |
public abstract void onEnterKeyDown(); | |
@Override | |
public boolean onKey(View v, int keyCode, KeyEvent event) | |
{ | |
if (keyCode != KeyEvent.KEYCODE_ENTER) | |
return false; | |
if (event.getAction() != KeyEvent.ACTION_DOWN) | |
return true; | |
onEnterKeyDown(); | |
return true; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment