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 DIFY API Endpoint 问题。
    • ¥20 sub地址DHCP问题
    • ¥15 delta降尺度计算的一些细节,有偿
    • ¥15 Arduino红外遥控代码有问题
    • ¥15 数值计算离散正交多项式
    • ¥30 数值计算均差系数编程
    • ¥15 redis-full-check比较 两个集群的数据出错
    • ¥15 Matlab编程问题
    • ¥15 训练的多模态特征融合模型准确度很低怎么办
    • ¥15 kylin启动报错log4j类冲突