如何在文本视图之间切换?

时间:2021-03-07 02:02:28

标签: string if-statement textview boolean findviewbyid

我应该添加什么才能在每次点击时在文本视图之间切换?它只适用于一键。这可能很容易解决,所以提前致谢!

    public void status(View view) {
        TextView textView2 = findViewById(R.id.textView2);
            if (textView2.getText() == "uhuh") {
                textView2.setText("u uh");
            } else {
                textView2.setText("u huh");
            }
    }

1 个答案:

答案 0 :(得分:0)

public void status(View view) {
        TextView textView2 = findViewById(R.id.textView2);
        String check = textView2.getText().toString();
        if (check.equals("u huh")) {
            textView2.setText("u uh");
        }
        else{
            textView2.setText("u huh");
        }
    }

相关问题