2016-11-21 62 views
2

如何獲取之前設置的textswitcher中的文本。就像textview.getText()一樣。我試過下面的代碼,但沒有工作。從TextSwitcher獲取文本

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

回答

3

參考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 
}