Skip to content

Most visited

Recently visited

navigation

EditText

public class EditText
extends TextView

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


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

Inherited XML attributes

From class android.widget.TextView
From class android.view.View

Inherited constants

From class android.view.View

Inherited fields

From class android.view.View

Public constructors

EditText(Context context)
EditText(Context context, AttributeSet attrs)
EditText(Context context, AttributeSet attrs, int defStyleAttr)
EditText(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes)

Public methods

void extendSelection(int index)

Convenience for extendSelection(Spannable, int).

CharSequence getAccessibilityClassName()

Return the class name of this object to be used for accessibility purposes.

boolean getFreezesText()

Return whether this text view is including its entire text contents in frozen icicles.

Editable getText()

Return the text the TextView is displaying.

void selectAll()

Convenience for selectAll(Spannable).

void setEllipsize(TextUtils.TruncateAt ellipsis)

Causes words in the text that are longer than the view's width to be ellipsized instead of broken in the middle.

void setSelection(int start, int stop)

Convenience for setSelection(Spannable, int, int).

void setSelection(int index)

Convenience for setSelection(Spannable, int).

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.

Inherited methods

From class android.widget.TextView
From class android.view.View
From class java.lang.Object
From interface android.view.ViewTreeObserver.OnPreDrawListener
From interface android.graphics.drawable.Drawable.Callback
From interface android.view.KeyEvent.Callback
From interface android.view.accessibility.AccessibilityEventSource

Public constructors

EditText

Added in API level 1
EditText (Context context)

Parameters
context Context

EditText

Added in API level 1
EditText (Context context, 
                AttributeSet attrs)

Parameters
context Context
attrs AttributeSet

EditText

Added in API level 1
EditText (Context context, 
                AttributeSet attrs, 
                int defStyleAttr)

Parameters
context Context
attrs AttributeSet
defStyleAttr int

EditText

Added in API level 21
EditText (Context context, 
                AttributeSet attrs, 
                int defStyleAttr, 
                int defStyleRes)

Parameters
context Context
attrs AttributeSet
defStyleAttr int
defStyleRes int

Public methods

extendSelection

Added in API level 1
void extendSelection (int index)

Convenience for extendSelection(Spannable, int).

Parameters
index int

getAccessibilityClassName

Added in API level 23
CharSequence getAccessibilityClassName ()

Return the class name of this object to be used for accessibility purposes. Subclasses should only override this if they are implementing something that should be seen as a completely new class of view when used by accessibility, unrelated to the class it is deriving from. This is used to fill in AccessibilityNodeInfo.setClassName.

Returns
CharSequence

getFreezesText

Added in API level 1
boolean getFreezesText ()

Return whether this text view is including its entire text contents in frozen icicles. For EditText it always returns true.

Returns
boolean Returns true if text is included, false if it isn't.

getText

Added in API level 1
Editable getText ()

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.

Returns
Editable

selectAll

Added in API level 1
void selectAll ()

Convenience for selectAll(Spannable).

setEllipsize

Added in API level 1
void setEllipsize (TextUtils.TruncateAt ellipsis)

Causes words in the text that are longer than the view's width to be ellipsized instead of broken in the middle. TextUtils.TruncateAt#MARQUEE is not supported.

Parameters
ellipsis TextUtils.TruncateAt: Type of ellipsis to be applied.
Throws
IllegalArgumentException When the value of ellipsis parameter is MARQUEE.

See also:

setSelection

Added in API level 1
void setSelection (int start, 
                int stop)

Convenience for setSelection(Spannable, int, int).

Parameters
start int
stop int

setSelection

Added in API level 1
void setSelection (int index)

Convenience for setSelection(Spannable, int).

Parameters
index int

setText

Added in API level 1
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.

Parameters
text CharSequence
type TextView.BufferType

Protected methods

getDefaultEditable

Added in API level 1
boolean getDefaultEditable ()

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

Returns
boolean

getDefaultMovementMethod

Added in API level 1
MovementMethod getDefaultMovementMethod ()

Subclasses override this to specify a default movement method.

Returns
MovementMethod
This site uses cookies to store your preferences for site-specific language and display options.

Hooray!

This class requires API level or higher

This doc is hidden because your selected API level for the documentation is . You can change the documentation API level with the selector above the left navigation.

For more information about specifying the API level your app requires, read Supporting Different Platform Versions.