protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button button = (Button) findViewById(R.id.button);
button.setOnClickListener(new Button.OnClickListener() {
public void onClick(View view) {
CheckBox yes = (CheckBox) findViewById(R.id.yes);
CheckBox no = (CheckBox) findViewById(R.id.no);
EditText ageText = (EditText) findViewById(R.id.ageText);
EditText editText = (EditText) findViewById(R.id.editText);
EditText editText3 = (EditText) findViewById(R.id.editText3);
int age;
age = 0;
if (yes.isChecked()) {
editText3.setText(age + 15);
} else if (no.isChecked()) {
editText3.setText(age - 10);
}
finish();
}
});
}
这段代码没有在 editText3 中给我任何输出。为什么会发生这种情况?代码没有错误,但仍然没有输出!
最佳答案
改变
button.setOnClickListener(new)onClickListener() ...
至
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
boolean checked = ((CheckBox) view).isChecked();
if (checkBox.isChecked()){
editText3.setText(age+15);
} else if (checkBox.isChecked()){
editText3.setText(age - 10);
}
}
});
关于java - EditText 中没有输出。为什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34693733/