EditText 中输入价格判断
mText.addTextChangedListener(new SimpleEditWatcher() { @Override public void afterTextChanged(Editable s) { final String text = s == null ? "" : s.toString(); mClickButton = !TextUtils.isEmpty(text.trim()); int index = text.indexOf("."); int index0 = text.indexOf("0"); if (index0 == 0 && text.substring(1).equals("0")) { mText.setText("0"); mText.setSelection(1); } if (index > 0) { if (text.length() > index + 3) { String payText = text.substring(0, index + 3); mText.setText(payText); mText.setSelection(payText.length()); } } else if (index == 0) { mText.setText(""); } if (!TextUtils.isEmpty(mText.getText().toString())) { float f = Float.parseFloat(mText.getText().toString()); if (f >= 1.00) { if (f < 1000000.00) { mClickButton = true; mMoney = mText.getText().toString(); checkSubmit(); } else { mText.setText(mMoney); mText.setSelection(mMoney.length()); mClickButton = false; checkSubmit(); } } else { mClickButton = false; checkSubmit(); } } else { mClickButton = false; checkSubmit(); } checkSubmit(); } });
时间: 2024-11-03 21:36:31