0

把我的头发拉在这里。无论选择哪个单选按钮,套餐价格始终为 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);
4

1 回答 1

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;
}
于 2013-06-17T19:27:00.793 回答