我为一个有7到8个字段的表单编写了一个程序,我想要做的是,假设我在EditText 1中输入一个值为50,而在EditText 2中输入为60,EditText 3应该是自动计算到3000而不点击任何按钮或执行任何事件 谁能建议我怎么做?
UPDATE firealarm SET Note=@Note
WHERE Note IS NULL
AND Col1 = @ValueOfCol1
AND Col2 = @ValueOfCol2
我知道我错了,但只是尝试了一下,并得到了数字格式异常
感谢你
答案 0 :(得分:2)
试试这段代码,
editDieselRate.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) {
Double v1 = Double.parseDouble(!editDieselRate.getText().toString().isEmpty() ?
editDieselRate.getText().toString() : "0");
Double v2 = Double.parseDouble(!editDieselQty.getText().toString().isEmpty() ?
editDieselQty.getText().toString() : "0");
Double value = v1 * v2;
editAmount.setText(value.toString());
}
});
b.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) {
Double v1 = Double.parseDouble(!editDieselRate.getText().toString().isEmpty() ?
editDieselRate.getText().toString() : "0");
Double v2 = Double.parseDouble(!editDieselQty.getText().toString().isEmpty() ?
editDieselQty.getText().toString() : "0");
Double value = v1 * v2;
editAmount.setText(value.toString());
}
});
同时检查editDieselQty或editDieselRate的值是否为数字,否则您将获得异常。我没有添加支票
答案 1 :(得分:0)
val mynum1: String = edtPrice.text.toString()
val mnum1 = mynum1.toFloat()
val mynum2: String = edtQuantity.text.toString()
val mnum2 = mynum2.toFloat()
val res = mnum1 * mnum2
txt_total?.text = res.toString()
您也可以尝试这个。