EditText에 Action Listener 다는 법

Posted by epicdev Archive : 2011. 9. 23. 03:07
mOutEditText.setOnEditorActionListener(mWriteListener);

private TextView.OnEditorActionListener mWriteListener = new TextView.OnEditorActionListener()
{
public boolean onEditorAction(TextView view, int actionId, KeyEvent event)
{
// If the action is a key-up event on the return key, send the message
if(actionId == EditorInfo.IME_NULL && event.getAction() == KeyEvent.ACTION_UP)
{
String message = view.getText().toString();
sendMessage(message);
}
if(D) Log.i(TAG, "END onEditorAction");
return true;
}
};

출처: http://developer.android.com/reference/android/widget/TextView.OnEditorActionListener.html

public static interface

TextView.OnEditorActionListener

android.widget.TextView.OnEditorActionListener

Class Overview

Interface definition for a callback to be invoked when an action is performed on the editor.

Summary

Public Methods
abstract boolean onEditorAction(TextView v, int actionId, KeyEvent event)
Called when an action is being performed.

Public Methods

public abstract boolean onEditorAction (TextView v, int actionId, KeyEvent event)

Since: API Level 3

Called when an action is being performed.

Parameters
vThe view that was clicked.
actionIdIdentifier of the action. This will be either the identifier you supplied, or EditorInfo.IME_NULL if being called due to the enter key being pressed.
eventIf triggered by an enter key, this is the event; otherwise, this is null.
Returns
  • Return true if you have consumed the action, else false.