Search code examples
androidtextviewtextswitcher

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();

Solution

  • 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
    }