to top
Android APIs
public class

CheckedTextView

extends TextView
implements Checkable
java.lang.Object
   ↳ android.view.View
     ↳ android.widget.TextView
       ↳ android.widget.CheckedTextView

Class Overview

An extension to TextView that supports the Checkable interface. This is useful when used in a ListView where the it's setChoiceMode has been set to something other than CHOICE_MODE_NONE.

Summary

XML Attributes
Attribute Name Related Method Description
android:checkMark setCheckMarkDrawable(int) Drawable used for the check mark graphic. 
android:checked Indicates the initial checked state of this text. 
[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
CheckedTextView(Context context)
CheckedTextView(Context context, AttributeSet attrs)
CheckedTextView(Context context, AttributeSet attrs, int defStyle)
Public Methods
Drawable getCheckMarkDrawable()
Gets the checkmark drawable
boolean isChecked()
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 onPaddingChanged(int layoutDirection)
Resolve padding depending on the layout direction.
void setCheckMarkDrawable(Drawable d)
Set the checkmark to a given Drawable.
void setCheckMarkDrawable(int resid)
Set the checkmark to a given Drawable, identified by its resourece id.
void setChecked(boolean checked)

Changes the checked state of this text view.

void setPadding(int left, int top, int right, int bottom)
Sets the padding.
void setPaddingRelative(int start, int top, int end, int bottom)
Sets the relative padding.
void toggle()
Change the checked state of the view to the inverse of its current state
Protected Methods
void drawableStateChanged()
This function is called whenever the state of the view changes in such a way that it impacts the state of drawables being shown.
int[] onCreateDrawableState(int extraSpace)
Generate the new Drawable state for this view.
void onDraw(Canvas canvas)
Implement this to do your drawing.
[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
From interface android.widget.Checkable

XML Attributes

android:checkMark

Drawable used for the check mark graphic.

Must be a reference to another resource, in the form "@[+][package:]type:name" or to a theme attribute in the form "?[package:][type:]name".

This corresponds to the global attribute resource symbol checkMark.

Related Methods

android:checked

Indicates the initial checked state of this text.

Must be a boolean value, either "true" or "false".

This may also be a reference to a resource (in the form "@[package:]type:name") or theme attribute (in the form "?[package:][type:]name") containing a value of this type.

This corresponds to the global attribute resource symbol checked.

Related Methods

Public Constructors

public CheckedTextView (Context context)

Since: API Level 1

public CheckedTextView (Context context, AttributeSet attrs)

Since: API Level 1

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

Since: API Level 1

Public Methods

public Drawable getCheckMarkDrawable ()

Since: API Level 16

Gets the checkmark drawable

Related XML Attributes
Returns
  • The drawable use to represent the checkmark, if any.

public boolean isChecked ()

Since: API Level 1

public void onInitializeAccessibilityEvent (AccessibilityEvent event)

Since: API Level 14

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)

Since: API Level 14

Initializes an AccessibilityNodeInfo with information about this view. The base implementation sets:

Subclasses should override this method, call the super implementation, and set additional attributes.

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

Parameters
info The instance to initialize.

public void onPaddingChanged (int layoutDirection)

Since: API Level 16

Resolve padding depending on the layout direction. Subclasses that care about padding resolution should override this method. The default implementation does nothing.

Parameters
layoutDirection the direction of the layout

public void setCheckMarkDrawable (Drawable d)

Since: API Level 1

Set the checkmark to a given Drawable. This will be drawn when isChecked() is true.

Related XML Attributes
Parameters
d The Drawable to use for the checkmark.

public void setCheckMarkDrawable (int resid)

Since: API Level 1

Set the checkmark to a given Drawable, identified by its resourece id. This will be drawn when isChecked() is true.

Related XML Attributes
Parameters
resid The Drawable to use for the checkmark.

public void setChecked (boolean checked)

Since: API Level 1

Changes the checked state of this text view.

Parameters
checked true to check the text, false to uncheck it

public void setPadding (int left, int top, int right, int bottom)

Since: API Level 1

Sets the padding. The view may add on the space required to display the scrollbars, depending on the style and visibility of the scrollbars. So the values returned from getPaddingLeft(), getPaddingTop(), getPaddingRight() and getPaddingBottom() may be different from the values set in this call.

Parameters
left the left padding in pixels
top the top padding in pixels
right the right padding in pixels
bottom the bottom padding in pixels

public void setPaddingRelative (int start, int top, int end, int bottom)

Since: API Level 16

Sets the relative padding. The view may add on the space required to display the scrollbars, depending on the style and visibility of the scrollbars. from the values set in this call.

Parameters
start the start padding in pixels
top the top padding in pixels
end the end padding in pixels
bottom the bottom padding in pixels

public void toggle ()

Since: API Level 1

Change the checked state of the view to the inverse of its current state

Protected Methods

protected void drawableStateChanged ()

Since: API Level 1

This function is called whenever the state of the view changes in such a way that it impacts the state of drawables being shown.

Be sure to call through to the superclass when overriding this function.

protected int[] onCreateDrawableState (int extraSpace)

Since: API Level 1

Generate the new Drawable state for this view. This is called by the view system when the cached Drawable state is determined to be invalid. To retrieve the current state, you should use getDrawableState().

Parameters
extraSpace if non-zero, this is the number of extra entries you would like in the returned array in which you can place your own states.
Returns
  • Returns an array holding the current Drawable state of the view.

protected void onDraw (Canvas canvas)

Since: API Level 1

Implement this to do your drawing.

Parameters
canvas the canvas on which the background will be drawn