我有一個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