我有一个onCheckedChanged
,它告诉我是否有RadioButton
在RadioGroup
被推送。字符串没有取值
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();
}
}
});
当我使用的是现在outcommented第一Toast
,它告诉我,TMP是“Männlich”或“Weiblich”。当我使用第二个Toast t1
,我告诉我geschlecht
是空的。 geschlecht的声明是在我的班级的顶部,因为我也需要它在我的onCreate
类。
为什么geschlecht没有采用tmp的价值?
检查条件与“equalsIgnoreCase”。 – pudaykiran 2013-05-06 08:53:24