我有一个onCheckedChanged
告诉我 aRadioButton
中的 aRadioGroup
是否被推。
RadioGroup rGroup = (RadioGroup)findViewById(R.id.rdgroup);
// This will get the radiobutton in the radiogroup that is checked
RadioButton checkedRadioButton = (RadioButton)rGroup.findViewById(rGroup.getCheckedRadioButtonId());
rGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener()
{
public void onCheckedChanged(RadioGroup rGroup, int checkedId)
{
// This will get the radiobutton that has changed in its check state
RadioButton checkedRadioButton = (RadioButton)rGroup.findViewById(checkedId);
// This puts the value (true/false) into the variable
boolean isChecked = checkedRadioButton.isChecked();
// If the radiobutton that has changed in check state is now checked...
if (isChecked)
{
String tmp = checkedRadioButton.getText().toString();
//Toast t = Toast.makeText(NeuesKind.this, checkedRadioButton.getText(), Toast.LENGTH_SHORT);
//
// t.show();
if(tmp == "Männlich"){
geschlecht = "männlich";
}
if(tmp == "Weiblich"){
geschlecht = "weiblich";
}
Toast t1 = Toast.makeText(NeuesKind.this, geschlecht, Toast.LENGTH_SHORT);
t1.show();
// Toast t = Toast.makeText(NeuesKind.this, checkedRadioButton.getText(), Toast.LENGTH_SHORT);
// t.show();
}
}
});
当我使用Toast
现在被淘汰的第一个时,它告诉我 tmp 是“Männlich”或“Weiblich”。当我使用第二个Toast t1
时,我告诉我geschlecht
是空的。geschlecht 的声明在我的课堂上是最重要的,因为我在onCreate
课堂上也需要它。
为什么 geschlecht 不采用 tmp 的值?