FileDocCategorySizeDatePackage
TextSwitcher.javaAPI DocAndroid 5.1 API3336Thu Mar 12 22:22:10 GMT 2015android.widget

TextSwitcher

public class TextSwitcher extends ViewSwitcher
Specialized {@link android.widget.ViewSwitcher} that contains only children of type {@link android.widget.TextView}. A TextSwitcher is useful to animate a label on screen. Whenever {@link #setText(CharSequence)} is called, TextSwitcher animates the current text out and animates the new text in.

Fields Summary
Constructors Summary
public TextSwitcher(android.content.Context context)
Creates a new empty TextSwitcher.

param
context the application's environment

        super(context);
    
public TextSwitcher(android.content.Context context, android.util.AttributeSet attrs)
Creates a new empty TextSwitcher for the given context and with the specified set attributes.

param
context the application environment
param
attrs a collection of attributes

        super(context, attrs);
    
Methods Summary
public voidaddView(android.view.View child, int index, ViewGroup.LayoutParams params)
{@inheritDoc}

throws
IllegalArgumentException if child is not an instance of {@link android.widget.TextView}

        if (!(child instanceof TextView)) {
            throw new IllegalArgumentException(
                    "TextSwitcher children must be instances of TextView");
        }

        super.addView(child, index, params);
    
public voidonInitializeAccessibilityEvent(android.view.accessibility.AccessibilityEvent event)

        super.onInitializeAccessibilityEvent(event);
        event.setClassName(TextSwitcher.class.getName());
    
public voidonInitializeAccessibilityNodeInfo(android.view.accessibility.AccessibilityNodeInfo info)

        super.onInitializeAccessibilityNodeInfo(info);
        info.setClassName(TextSwitcher.class.getName());
    
public voidsetCurrentText(java.lang.CharSequence text)
Sets the text of the text view that is currently showing. This does not perform the animations.

param
text the new text to display

        ((TextView)getCurrentView()).setText(text);
    
public voidsetText(java.lang.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.

param
text the new text to display

        final TextView t = (TextView) getNextView();
        t.setText(text);
        showNext();