从 TextSwitcher 获取文本

Getting text from TextSwitcher

如何获取之前设置的文本切换器中的文本。就像 textview.getText() 一样。我尝试了以下代码但没有用。

TextSwitcher textSwitcher = (TextSwitcher)findViewById(...);
TextView currentlyShownTextView = (TextView) textSwitcher.getCurrentView();
String currentlyShownText = textSwitcher.getText().toString();

参考this回答

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
}