左晓为主开发手持机充值管理机
zuoxiao
2024-03-07 389d1e5aedc99a3909c61db855b18a2936919942
app/src/main/java/com/dayu/recharge/activity/ElectricPriceActivity.java
@@ -1,7 +1,9 @@
package com.dayu.recharge.activity;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.view.LayoutInflater;
import android.view.View;
@@ -25,7 +27,43 @@
        super.onCreate(savedInstanceState);
        electricPriceBinding = ActivityElectricPriceBinding.inflate(LayoutInflater.from(this));
        setContentView(electricPriceBinding.getRoot());
        initView();
        initData();
    }
    private void initView() {
        //保留三位小数
        electricPriceBinding.electricNewNum.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) {
                // 删除额外的小数位
                String text = s.toString();
                if (text.contains(".")) {
                    int decimalIndex = text.indexOf(".");
                    int decimalCount = text.length() - decimalIndex - 1;
                    if (decimalCount > 3) {
                        s.delete(decimalIndex + 4, s.length());
                    }
                }
            }
        });
        electricPriceBinding.electricOk.setOnClickListener(new View.OnClickListener() {
            @Override
@@ -40,8 +78,6 @@
                }
            }
        });
    }
    private void initData() {