websholl 2015-10-13 14:15 采纳率: 50%
浏览 1486

BillTotal有问题,但是我又找不到,求助

图片说明
public class T_Calculator extends Activity{
private static final String BILL_TOTAL = "BILL_TOTAL";
private static final String CUSTOM_PERCENT = "CUSTOM_PERCENT";

private double currentBillTotal;
private int currentCustomPercent;
private EditText Tip10_et;
private EditText Tip15_et;
private EditText Tip20_et;
private EditText Total10_et;
private EditText Total15_et;
private EditText Total20_et;
private EditText Bt_et;
private TextView CustomTip_tv;
private EditText TipCustom_et;
private EditText TotalCustom_et;
public void onCreate(Bundle savedInstanceState){
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_t__calculator);
    //
    if (savedInstanceState == null)
    {
        currentBillTotal = 0.0;
        currentCustomPercent = 18;
    }
    else {
        currentBillTotal = savedInstanceState.getDouble(BILL_TOTAL);
        currentCustomPercent = savedInstanceState.getInt(CUSTOM_PERCENT);
    }
    Tip10_et = (EditText) findViewById(R.id.Tip10_et);
    Total10_et = (EditText)findViewById(R.id.Total10_et);
    Tip15_et = (EditText)findViewById(R.id.Tip15_et);
    Total15_et = (EditText)findViewById(R.id.Total15_et);
    Tip20_et = (EditText)findViewById(R.id.Tip20_et);
    Total20_et = (EditText)findViewById(R.id.Total20_et);
    CustomTip_tv = (TextView)findViewById(R.id.CustomTip_tv);
    TipCustom_et = (EditText) findViewById(R.id.TipCustom_et);
    TotalCustom_et = (EditText) findViewById(R.id.TotalCustom_et);
    Bt_et = (EditText) findViewById(R.id.Bt_et);
    Bt_et.addTextChangedListener(Bt_etWatcher);
    SeekBar Custom_Sb = (SeekBar) findViewById(R.id.Custom_Sb);
    Custom_Sb.setOnSeekBarChangeListener(Custom_SbListener);
}
public void updateStandard(){
    Double tenPercentTip = currentBillTotal * .1;
    Double tenPercentTotal = currentBillTotal + tenPercentTip;
    //
    Tip10_et.setText(String.format("%.02f", tenPercentTip));
    Total10_et.setText(String.format("%.02f", tenPercentTotal));
    //
    Double fifteenPercentTip = currentBillTotal * .15;
    Double fifteenPercentTotal = currentBillTotal + fifteenPercentTip;
    Tip15_et.setText(String.format("%.02f", fifteenPercentTip));
    Total15_et.setText(String.format("%.02f", fifteenPercentTotal));
    //
    Double twentyPercentTip = currentBillTotal * .20;
    Double twentyPercentTotal = currentBillTotal + twentyPercentTip;
    Tip20_et.setText(String.format("%.02f", twentyPercentTip));
    Total20_et.setText(String.format("%.02f", twentyPercentTotal));
}
public void updateCustom(){
    CustomTip_tv.setText(currentCustomPercent + "%");
    Double customTipAmount = currentBillTotal * currentCustomPercent * .01;
    Double customTotalAmount = currentBillTotal + customTipAmount;
    TipCustom_et.setText(String.format("%.02f", customTipAmount));
    TotalCustom_et.setText(String.format("%.02f", customTotalAmount));
}
public void onSaveInstanceState(Bundle outState){
    super.onSaveInstanceState(outState);
    outState.putDouble(BILL_TOTAL , currentBillTotal);
    outState.putInt(CUSTOM_PERCENT , currentCustomPercent);
}
private SeekBar.OnSeekBarChangeListener Custom_SbListener =
        new SeekBar.OnSeekBarChangeListener() {
            @Override
            public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
                currentCustomPercent = seekBar.getProgress();
                updateCustom();
            }

            @Override
            public void onStartTrackingTouch(SeekBar seekBar) {

            }

            @Override
            public void onStopTrackingTouch(SeekBar seekBar) {

            }
        };
private TextWatcher Bt_etWatcher = new TextWatcher() {
    @Override
    public void beforeTextChanged(CharSequence s, int start, int count, int after) {
        try {
            currentBillTotal = Double.parseDouble(s.toString());
        }
        catch (NumberFormatException e){
            currentBillTotal = 0.0;
        }
        updateCustom();
        updateStandard();
    }

    @Override
    public void onTextChanged(CharSequence s, int start, int before, int count) {

    }

    @Override
    public void afterTextChanged(Editable s) {

    }
};

}


  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 微信会员卡等级和折扣规则
    • ¥15 微信公众平台自制会员卡可以通过收款码收款码收款进行自动积分吗
    • ¥15 随身WiFi网络灯亮但是没有网络,如何解决?
    • ¥15 gdf格式的脑电数据如何处理matlab
    • ¥20 重新写的代码替换了之后运行hbuliderx就这样了
    • ¥100 监控抖音用户作品更新可以微信公众号提醒
    • ¥15 UE5 如何可以不渲染HDRIBackdrop背景
    • ¥70 2048小游戏毕设项目
    • ¥20 mysql架构,按照姓名分表
    • ¥15 MATLAB实现区间[a,b]上的Gauss-Legendre积分