I´ve got an onCheckedChanged
that tells me if a RadioButton
in a RadioGroup
is pushed.
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();
}
}
});
When I use the first Toast
that is outcommented now, it tells me that tmp is "Männlich" or "Weiblich". When I use the second Toast t1
, i tells me geschlecht
is empty.
The declaration of geschlecht is at the very top of my class because I also need it in my onCreate
class.
Why does geschlecht doesn´t take the value of tmp?