Please note that the contents of this offline web site may be out of date. To access the most recent documentation visit the online version .
Note that links that point to online resources are green in color and will open in a new window.
We would love it if you could give us feedback about this material by filling this form (You have to be online to fill it)
Android APIs
public class

EditText

extends TextView
java.lang.Object
   ↳ android.view.View
     ↳ android.widget.TextView
       ↳ android.widget.EditText
Known Direct Subclasses
Known Indirect Subclasses

Class Overview

EditText is a thin veneer over TextView that configures itself to be editable.

See the Text Fields guide.

XML attributes

See EditText Attributes , TextView Attributes , View Attributes

Summary

[Expand]
Inherited XML Attributes
From class android.widget.TextView
From class android.view.View
[Expand]
Inherited Constants
From class android.view.View
[Expand]
Inherited Fields
From class android.view.View
Public Constructors
EditText ( Context context)
EditText ( Context context, AttributeSet attrs)
EditText ( Context context, AttributeSet attrs, int defStyle)
Public Methods
void extendSelection (int index)
Editable getText ()
Return the text the TextView is displaying.
void onInitializeAccessibilityEvent ( AccessibilityEvent event)
Initializes an AccessibilityEvent with information about this View which is the event source.
void onInitializeAccessibilityNodeInfo ( AccessibilityNodeInfo info)
Initializes an AccessibilityNodeInfo with information about this view.
void selectAll ()
Convenience for selectAll(Spannable) .
void setEllipsize ( TextUtils.TruncateAt ellipsis)
Causes words in the text that are longer than the view is wide to be ellipsized instead of broken in the middle.
void setSelection (int index)
void setSelection (int start, int stop)
void setText ( CharSequence text, TextView.BufferType type)
Sets the text that this TextView is to display (see setText(CharSequence) ) and also sets whether it is stored in a styleable/spannable buffer and whether it is editable.
Protected Methods
boolean getDefaultEditable ()
Subclasses override this to specify that they have a KeyListener by default even if not specifically called for in the XML options.
MovementMethod getDefaultMovementMethod ()
Subclasses override this to specify a default movement method.
[Expand]
Inherited Methods
From class android.widget.TextView
From class android.view.View
From class java.lang.Object
From interface android.graphics.drawable.Drawable.Callback
From interface android.view.KeyEvent.Callback
From interface android.view.ViewTreeObserver.OnPreDrawListener
From interface android.view.accessibility.AccessibilityEventSource

Public Constructors

public EditText ( Context context)

Added in API level 1

public EditText ( Context context, AttributeSet attrs)

Added in API level 1

public EditText ( Context context, AttributeSet attrs, int defStyle)

Added in API level 1

Public Methods

public void extendSelection (int index)

Added in API level 1

public Editable getText ()

Added in API level 1

Return the text the TextView is displaying. If setText() was called with an argument of BufferType.SPANNABLE or BufferType.EDITABLE, you can cast the return value from this method to Spannable or Editable, respectively. Note: The content of the return value should not be modified. If you want a modifiable one, you should make your own copy first.

public void onInitializeAccessibilityEvent ( AccessibilityEvent event)

Initializes an AccessibilityEvent with information about this View which is the event source. In other words, the source of an accessibility event is the view whose state change triggered firing the event.

Example: Setting the password property of an event in addition to properties set by the super implementation:

          public void onInitializeAccessibilityEvent(AccessibilityEvent event) {
     super.onInitializeAccessibilityEvent(event);
     event.setPassword(true);
 }
         

If an View.AccessibilityDelegate has been specified via calling setAccessibilityDelegate(AccessibilityDelegate) its onInitializeAccessibilityEvent(View, AccessibilityEvent) is responsible for handling this call.

Note: Always call the super implementation before adding information to the event, in case the default implementation has basic information to add.

Parameters
event The event to initialize.

public void onInitializeAccessibilityNodeInfo ( AccessibilityNodeInfo info)

Parameters
info The instance to initialize.

public void selectAll ()

Added in API level 1

Convenience for selectAll(Spannable) .

public void setEllipsize ( TextUtils.TruncateAt ellipsis)

Added in API level 1

Causes words in the text that are longer than the view is wide to be ellipsized instead of broken in the middle. You may also want to setSingleLine() or setHorizontallyScrolling(boolean) to constrain the text to a single line. Use null to turn off ellipsizing. If setMaxLines(int) has been used to set two or more lines, END and MARQUEE * are only supported (other ellipsizing types will not do anything).

public void setSelection (int index)

Added in API level 1

public void setSelection (int start, int stop)

Added in API level 1

public void setText ( CharSequence text, TextView.BufferType type)

Added in API level 1

Sets the text that this TextView is to display (see setText(CharSequence) ) and also sets whether it is stored in a styleable/spannable buffer and whether it is editable.

Protected Methods

protected boolean getDefaultEditable ()

Added in API level 1

Subclasses override this to specify that they have a KeyListener by default even if not specifically called for in the XML options.

protected MovementMethod getDefaultMovementMethod ()

Added in API level 1

Subclasses override this to specify a default movement method.