[ Web Proxy ]
URL:
Viewing: https://developer.android.com/reference/android/text/method/BaseKeyListener [Back]  [Original]

BaseKeyListener  |  API reference  |  Android Developers Skip to main content
Essentials Design & Plan Develop Google Play Blog
Search:
Android Studio
Android Developers [Android Developers]
Stay organized with collections Save and categorize content based on your preferences.

BaseKeyListener


public abstract class BaseKeyListener
extends MetaKeyKeyListener implements KeyListener

java.lang.Object
   ↳ android.text.method.MetaKeyKeyListener
     ↳ android.text.method.BaseKeyListener


Abstract base class for key listeners. Provides a basic foundation for entering and editing text. Subclasses should override onKeyDown(View, Editable, int, KeyEvent) and MetaKeyKeyListener.onKeyUp(View, Editable, int, KeyEvent) to insert characters as keys are pressed.

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

Inherited constants

Public constructors

BaseKeyListener()

Public methods

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

Performs the action that happens when you press the KeyEvent.KEYCODE_DEL key in a TextView.

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

Performs the action that happens when you press the KeyEvent.KEYCODE_FORWARD_DEL key in a TextView.

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.

Inherited methods

Public constructors

BaseKeyListener

public BaseKeyListener ()

Public methods

backspace

Added in API level 1
public boolean backspace (View view, 
                Editable content, 
                int keyCode, 
                KeyEvent event)

Performs the action that happens when you press the KeyEvent.KEYCODE_DEL key in a TextView. If there is a selection, deletes the selection; otherwise, deletes the character before the cursor, if any; ALT+DEL deletes everything on the line the cursor is on.

Parameters
view View

content Editable

keyCode int

event KeyEvent

Returns
boolean true if anything was deleted; false otherwise.

forwardDelete

Added in API level 11
public boolean forwardDelete (View view, 
                Editable content, 
                int keyCode, 
                KeyEvent event)

Performs the action that happens when you press the KeyEvent.KEYCODE_FORWARD_DEL key in a TextView. If there is a selection, deletes the selection; otherwise, deletes the character before the cursor, if any; ALT+FORWARD_DEL deletes everything on the line the cursor is on.

Parameters
view View

content Editable

keyCode int

event KeyEvent

Returns
boolean true if anything was deleted; false otherwise.

onKeyDown

Added in API level 1
public boolean onKeyDown (View view, 
                Editable content, 
                int keyCode, 
                KeyEvent event)

Handles presses of the meta keys.

Parameters
view View

content Editable

keyCode int

event KeyEvent

Returns
boolean

onKeyOther

Added in API level 3
public boolean onKeyOther (View view, 
                Editable content, 
                KeyEvent event)

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

Parameters
view View

content Editable

event KeyEvent

Returns
boolean

Content and code samples on this page are subject to the licenses described in the Content License. Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.

Last updated 2026-08-03 UTC.

[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2026-08-03 UTC."],[],[]]

Web Proxy Viewer  |  New URL  |  Original Page