项目中遇到的 记录下以防忘记 实时监听文本框的值并计算
private double height=0;
private double weight=0;
private double weightcur=0;
mViewBinding.edFollowupHeight.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 (!TextUtils.isEmpty(s)) {
height = Double.parseDouble(s.toString());
if (height > 0) {
try {
if (!TextUtils.isEmpty(mViewBinding.edFollowupWeight.getText().toString())) {
weight=Double.parseDouble(mViewBinding.edFollowupWeight.getText().toString());
mViewBinding.edFollowupBMI.setText(div(weight, mul(height / 100, height / 100), 2) + "");
}