Android Open Source - AerisAndroidLibrary Edit Text Enter Listener

From Project

Back to project page AerisAndroidLibrary.


The source code is released under:

Apache License

If you think the Android project AerisAndroidLibrary listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.example.edithelp; 
//from  ww  w  .j a v  a  2s .c  o m
import android.content.Context;
import android.view.KeyEvent;
import android.view.View;
import android.view.View.OnKeyListener;
import android.view.inputmethod.InputMethodManager;
import android.widget.EditText;

 * Listener for the enter pressed on a keyboard for a EditText. 
 * @author bcollins
public class EditTextEnterListener implements OnKeyListener{
   * Delegate to trigger method call when enter is pressed. 
  protected EnterPressedDelegate delegate; 
   * Constructor for the listener
   * @param delegate
  public EditTextEnterListener(EnterPressedDelegate delegate){
    this.delegate = delegate;
   * (non-Javadoc)
   * @see android.view.View.OnKeyListener#onKey(android.view.View, int, android.view.KeyEvent)
  public boolean onKey(View v, int keyCode, KeyEvent event) {
        if (event.getAction() == KeyEvent.ACTION_DOWN)
            switch (keyCode)
                case KeyEvent.KEYCODE_DPAD_CENTER:
                case KeyEvent.KEYCODE_ENTER:
                  InputMethodManager imm = (InputMethodManager)v.getContext()
                  imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
                  //Passes the button that was pressed to handle the event
                  delegate.onEnterPressed(v.getId(), (EditText)v); 
                    return true;
        return false;


Java Source Code List