Android APIs
public class

TextKeyListener

extends BaseKeyListener
implements SpanWatcher
java.lang.Object
   ↳ android.text.method.MetaKeyKeyListener
     ↳ android.text.method.BaseKeyListener
       ↳ android.text.method.TextKeyListener

Class Overview

This is the key listener for typing normal text. It delegates to other key listeners appropriate to the current keyboard and language.

As for all implementations of KeyListener, this class is only concerned with hardware keyboards. Software input methods have no obligation to trigger the methods in this class.

Summary

Nested Classes
enum TextKeyListener.Capitalize  
[Expand]
Inherited Constants
From class android.text.method.MetaKeyKeyListener
Public Constructors
TextKeyListener(TextKeyListener.Capitalize cap, boolean autotext)
Creates a new TextKeyListener with the specified capitalization and correction properties.
Public Methods
static void clear(Editable e)
Clear all the input state (autotext, autocap, multitap, undo) from the specified Editable, going beyond Editable.clear(), which just clears the text but not the input state.
int getInputType()
static TextKeyListener getInstance()
Returns a new or existing instance with no automatic capitalization or correction.
static TextKeyListener getInstance(boolean autotext, TextKeyListener.Capitalize cap)
Returns a new or existing instance with the specified capitalization and correction properties.
boolean onKeyDown(View view, Editable content, int keyCode, KeyEvent event)
Handles presses of the meta keys.
boolean onKeyOther(View view, Editable content, KeyEvent event)
Base implementation handles ACTION_MULTIPLE KEYCODE_UNKNOWN by inserting the event's text into the content.
boolean onKeyUp(View view, Editable content, int keyCode, KeyEvent event)
Handles release of the meta keys.
void onSpanAdded(Spannable s, Object what, int start, int end)
This method is called to notify you that the specified object has been attached to the specified range of the text.
void onSpanChanged(Spannable s, Object what, int start, int end, int st, int en)
This method is called to notify you that the specified object has been relocated from the range ostart…oend to the new range nstart…nend of the text.
void onSpanRemoved(Spannable s, Object what, int start, int end)
This method is called to notify you that the specified object has been detached from the specified range of the text.
void release()
static boolean shouldCap(TextKeyListener.Capitalize cap, CharSequence cs, int off)
Returns whether it makes sense to automatically capitalize at the specified position in the specified text, with the specified rules.
[Expand]
Inherited Methods
From class android.text.method.BaseKeyListener
From class android.text.method.MetaKeyKeyListener
From class java.lang.Object
From interface android.text.SpanWatcher
From interface android.text.method.KeyListener

Public Constructors

public TextKeyListener (TextKeyListener.Capitalize cap, boolean autotext)

Added in API level 1

Creates a new TextKeyListener with the specified capitalization and correction properties.

Parameters
cap when, if ever, to automatically capitalize.
autotext whether to automatically do spelling corrections.

Public Methods

public static void clear (Editable e)

Added in API level 1

Clear all the input state (autotext, autocap, multitap, undo) from the specified Editable, going beyond Editable.clear(), which just clears the text but not the input state.

Parameters
e the buffer whose text and state are to be cleared.

public int getInputType ()

Added in API level 3

public static TextKeyListener getInstance ()

Added in API level 1

Returns a new or existing instance with no automatic capitalization or correction.

public static TextKeyListener getInstance (boolean autotext, TextKeyListener.Capitalize cap)

Added in API level 1

Returns a new or existing instance with the specified capitalization and correction properties.

Parameters
autotext whether to automatically do spelling corrections.
cap when, if ever, to automatically capitalize.

public boolean onKeyDown (View view, Editable content, int keyCode, KeyEvent event)

Added in API level 1

Handles presses of the meta keys.

public boolean onKeyOther (View view, Editable content, KeyEvent event)

Added in API level 3

Base implementation handles ACTION_MULTIPLE KEYCODE_UNKNOWN by inserting the event's text into the content.

public boolean onKeyUp (View view, Editable content, int keyCode, KeyEvent event)

Added in API level 1

Handles release of the meta keys.

public void onSpanAdded (Spannable s, Object what, int start, int end)

Added in API level 1

This method is called to notify you that the specified object has been attached to the specified range of the text.

public void onSpanChanged (Spannable s, Object what, int start, int end, int st, int en)

Added in API level 1

This method is called to notify you that the specified object has been relocated from the range ostart…oend to the new range nstart…nend of the text.

public void onSpanRemoved (Spannable s, Object what, int start, int end)

Added in API level 1

This method is called to notify you that the specified object has been detached from the specified range of the text.

public void release ()

Added in API level 1

public static boolean shouldCap (TextKeyListener.Capitalize cap, CharSequence cs, int off)

Added in API level 1

Returns whether it makes sense to automatically capitalize at the specified position in the specified text, with the specified rules.

Parameters
cap the capitalization rules to consider.
cs the text in which an insertion is being made.
off the offset into that text where the insertion is being made.
Returns
  • whether the character being inserted should be capitalized.