把头发拉出来。无论选择什么单选按钮,套餐价格总是达到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);
答案 0 :(得分:0)
使用String.equals()方法比较字符串对象:
if(display_package_selected.equals("Bronze"))
{
package_price = 150.00;
}
else if(display_package_selected.equals("Silver"))
{
package_price = 225.00;
}
else if(display_package_selected.equals("Gold"))
{
package_price = 375.00;
}
else
{
package_price = 525.00;
}