| | |
| | | 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; |
| | | |
| | |
| | | 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 |
| | |
| | | } |
| | | } |
| | | }); |
| | | |
| | | |
| | | } |
| | | |
| | | private void initData() { |