求助,應用不管選中哪個按鈕,價格總是525.00。不知道怎麼搞的。
//Get and set package selected.
radioPackageGroup = (RadioGroup) findViewById(R.id.radTadPackage);
int selectedId = radioPackageGroup.getCheckedRadioButtonId();
btnPackage = (RadioButton) findViewById(selectedId);
String display_package_selected = btnPackage.getText().toString();
TadGlobals.getTadPackageInstance().setTadPackage(display_package_selected);
//Set package price.
double package_price = 0.00;
if(display_package_selected == "Bronze"){
package_price = 150.00;
}else if(display_package_selected == "Silver"){
package_price = 225.00;
}else if(display_package_selected == "Gold"){
package_price = 375.00;
}else{
package_price = 525.00;
}
TadGlobals.getPackagePriceInstance().setPackagePrice(package_price);
很顯然,你這個是在初始化做的,獲取btn的按鈕的值
而你並沒有寫選中的監聽事件
a.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(RadioGroup radioGroup, int i) {
//To change body of implemented methods use File | Settings | File Templates.
}
});
然後按照樓下的代碼區設置