Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting text from TextSwitcher

How can I get the text in textswitcher which is previously set. Just like textview.getText(). I have tried the following code but didn't work.

TextSwitcher textSwitcher = (TextSwitcher)findViewById(...);
TextView currentlyShownTextView = (TextView) textSwitcher.getCurrentView();
String currentlyShownText = textSwitcher.getText().toString();
like image 282
ndn Avatar asked Nov 21 '16 06:11

ndn


People also ask

What is TextSwitcher?

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.

What is TextSwitcher in Android?

In Android, TextSwitcher is a specialized ViewSwitcher that contains only children of type TextView. TextSwitcher is available in Android from version Android 1.6+. A TextSwitcher is useful to animate a label(i.e. text) on screen. It is an element of transition widget which helps us to add transitions on the labels.


1 Answers

Refer this answer

TextSwitcher twTime = (TextSwitcher) findViewById(R.id.textSwotcher);
twTime.setCurrentText("your text");
TextView tv = (TextView) twTime.getCurrentView();
if (tv.getText().toString().length()>0) {
    //your action here
}
like image 155
SaravInfern Avatar answered Oct 08 '22 17:10

SaravInfern