TextSwitcher


public class TextSwitcher
extends ViewSwitcher

java.lang.Object
   ↳ android.view.View
     ↳ android.view.ViewGroup
       ↳ android.widget.FrameLayout
         ↳ android.widget.ViewAnimator
           ↳ android.widget.ViewSwitcher
             ↳ android.widget.TextSwitcher


Specialized ViewSwitcher that contains only children of type TextView. A TextSwitcher is useful to animate a label on screen. Whenever setText(java.lang.CharSequence) is called, TextSwitcher animates the current text out and animates the new text in.

Summary

Inherited XML attributes

Inherited constants

Inherited fields

Public constructors

TextSwitcher(Context context)

Creates a new empty TextSwitcher.

TextSwitcher(Context context, AttributeSet attrs)

Creates a new empty TextSwitcher for the given context and with the specified set attributes.

Public methods

void addView(View child, int index, ViewGroup.LayoutParams params)

Adds a child view with the specified layout parameters.

CharSequence getAccessibilityClassName()

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

void setCurrentText(CharSequence text)

Sets the text of the text view that is currently showing.

void setText(CharSequence text)

Sets the text of the next view and switches to the next view.

Inherited methods

Public constructors

TextSwitcher

Added in API level 1
public TextSwitcher (Context context)

Creates a new empty TextSwitcher.

Parameters
context Context: the application's environment

TextSwitcher

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

Creates a new empty TextSwitcher for the given context and with the specified set attributes.

Parameters
context Context: the application environment

attrs AttributeSet: a collection of attributes

Public methods

addView

Added in API level 1
public void addView (View child, 
                int index, 
                ViewGroup.LayoutParams params)

Adds a child view with the specified layout parameters.

Note: do not invoke this method from View.draw(android.graphics.Canvas), View.onDraw(android.graphics.Canvas), dispatchDraw(android.graphics.Canvas) or any related method.

Parameters
child View: the child view to add

index int: the position at which to add the child or -1 to add last

params ViewGroup.LayoutParams: the layout parameters to set on the child

Throws
IllegalArgumentException if child is not an instance of TextView

getAccessibilityClassName

Added in API level 23
public 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

setCurrentText

Added in API level 1
public void setCurrentText (CharSequence text)

Sets the text of the text view that is currently showing. This does not perform the animations.

Parameters
text CharSequence: the new text to display

setText

Added in API level 1
public void setText (CharSequence text)

Sets the text of the next view and switches to the next view. This can be used to animate the old text out and animate the next text in.

Parameters
text CharSequence: the new text to display