当我删除e2中的值以进行另一次计算时,应用程序将崩溃,因为e4和e5正在尝试对非数字执行计算,我应该添加什么代码?
private void hookButtons() {
e2 = findViewById(R.id.SalePriceNum);
e4 = findViewById(R.id.ebayFeeNum);
e5 = findViewById(R.id.paypalFeeNum);
e2.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
}
@Override
public void afterTextChanged(Editable s) {
if (e2.getText().toString() != "")
{
double salePrice = Double.parseDouble(e2.getText().toString());
double ebayFee = salePrice / 10.00;
double paypalFee = (salePrice * 0.034) + 0.2;
double roundedPPFee = Math.round(paypalFee*100.00)/100.00;
double roundedEbayFee = Math.round(ebayFee*100.00)/100.00;
e4.setText(String.valueOf(roundedEbayFee));
e5.setText(String.valueOf(roundedPPFee));
}
}
});
}