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

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) {

    }
};

}


  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

相关推荐 更多相似问题