如何为 Android setText()
命令创建 if
语句?
例如,如果我有类似的内容:
Button button = (Button) findViewById(R.id.button);
TextView messageBox = (TextView)findViewById(R.id.message);
phrase[0] = "Hello World!"; //
phrase[1] = "Toast"; // array is declared earlier in code
Random r = new Random();
int n = r.nextInt(1);
messageBox.setText(phrase[n]);
if(/*condition when phrase[1] is displayed in messageBox*/){
// do stuff
}
我的想法是,我想构造一个 if
语句来监视特定消息何时显示在我的 messageBox
对象中。
最佳答案
试试这个:
Button button = (Button) findViewById(R.id.button);
TextView messageBox = (TextView)findViewById(R.id.message);
phrase[0] = "Hello World!"; //
phrase[1] = "Toast"; // array is declared earlier in code
Random r = new Random();
int n = r.nextInt(1);
messageBox.setText(phrase[0]);
if(messageBox.getText().toString().equals("Toast")){
// do stuff
}
关于java - Android TextView消息显示的If语句,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32060891/