【发布时间】:2014-12-21 14:43:04
【问题描述】:
我只是通过场景来尝试和帮助,我希望能够推送 b1 并将其更改/setText 为 t1,除非 t3 由于 b2 而发生更改。当这种情况发生时,我希望它为 t2 设置文本。我用许多不同的方法来检查 t3 是否已更改但没有流行,我已经尽可能简单地制作了这个应用程序。我试过 while 语句和 str.matches(t3)。
谢谢,理想情况下,我希望能够通过检查 t3 的内容而不是使用切换来做到这一点,但我已经提供了带有切换的代码,以表明它不能使用它。
提前致谢:)
public class MyActivity extends Activity {
Button b1, b2;
TextView t1, t2, t3;
String str, str1;
ToggleButton toggle;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_my);
b1 = (Button) findViewById(R.id.button);
b2 = (Button) findViewById(R.id.button2);
t1 = (TextView) findViewById(R.id.textView1);
t2 = (TextView) findViewById(R.id.textView2);
t3 = (TextView) findViewById(R.id.textView3);
toggle = (ToggleButton) findViewById(R.id.toggle);
str1 = t3.getText().toString();
b2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
t3.setText("Hello");
toggle.setChecked(true);
}
});
{
if (toggle.isChecked() == true) {
b1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
t2.setText("Success!");
}
});
} else if (toggle.isChecked() == false) {
b1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
str = t1.getText().toString();
t1.setText(str + "1");
}
});
}
}
}
【问题讨论】:
标签: java android eclipse android-studio