当前位置:网站首页>EditText 金额限制
EditText 金额限制
2022-06-11 17:49:00 【xiaoerbuyu1233】
mEdtOilHeightWarning.addTextChangedListener(getWatcher(mEdtOilHeightWarning));
android:inputType="numberDecimal"private TextWatcher getWatcher(EditText edt) {
return 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) {
String text = s.toString();
if (TextUtils.isEmpty(text)) {
return;
}
if (text.startsWith("00")) {
edt.setText(text.replace("00", "0"));//去除00开头
}
if (text.startsWith("0") && text.length() >= 2 && !".".equals(text.charAt(1) + "")) {
edt.setText(text.substring(1));//替换整数0开头 输入01显示1
}
if (text.startsWith(".")) {
edt.setText(String.format("0%s", text));//.开头替换为0.开头
}
if (text.contains(".") && (text.length() - text.indexOf(".")) > 3) {
edt.setText(text.substring(0, text.length() - 1));//保留两位小说
}
if (text.length() > 7) {
edt.setText(text.substring(0, text.length() - 1));//长度7位
}
edt.setSelection(edt.getText().length());//不能用 text.length() 否则输入00索引异常
}
@Override
public void afterTextChanged(Editable s) {
}
};
}输入 . 追加0
00开头替换为0
0开头并且第二位不是.的情况下去除开头的0
边栏推荐
- About element location and size
- [practical Script] obtain the line number of a file, and then delete the file content.
- SQL报错注入1
- [collect first and use it sooner or later] 49 Flink high-frequency interview questions series (II)
- Merge two ordered linked lists ---2022/02/24
- Winter vacation daily question 2022 [week1 not finished]
- Delete the penultimate node of the linked list ---2022/02/22
- Spring 2021 daily question [week5 not finished]
- ctf入门
- Network Security Threat Intelligence System
猜你喜欢

Ffmpeg parity field frame interlace progressive command and code processing
![[collect first and use it sooner or later] 100 Flink high-frequency interview questions series (II)](/img/cf/44b3983dd5d5f7b92d90d918215908.png)
[collect first and use it sooner or later] 100 Flink high-frequency interview questions series (II)
![Spring 2021 daily question [end of week4]](/img/b3/2f5a66b0d4374db3d4db0b71d72f7e.jpg)
Spring 2021 daily question [end of week4]

送给大模型的「高考」卷:442人联名论文给大模型提出204个任务,谷歌领衔

How ZABBIX can customize MySQL monitoring items and trigger alarms

【先收藏,早晚用得到】100个Flink高频面试题系列(一)
![Codeworks round 479 (Div. 3) [done]](/img/a0/f3c6989d8f755c03076b237514ee64.jpg)
Codeworks round 479 (Div. 3) [done]
![Intelligent overall legend, legend of wiring, security, radio conference, television, building, fire protection and electrical diagram [transferred from wechat official account weak current classroom]](/img/c7/2f4bdad149f547c1f651ed4bf93dee.png)
Intelligent overall legend, legend of wiring, security, radio conference, television, building, fire protection and electrical diagram [transferred from wechat official account weak current classroom]
![Winter vacation daily question (improvement group) [end of week 4]](/img/67/89b5164712d8c4eb319b9266dd4b91.jpg)
Winter vacation daily question (improvement group) [end of week 4]

upload-labs通关未半而中道崩殂
随机推荐
6-6 batch sum (*)
Service learning notes 03 front desk service practice
【先收藏,早晚用得到】100个Flink高频面试题系列(二)
Système d'information sur les menaces à la sécurité des réseaux
Chorus translation
Service learning notes 04 other service implementation methods and alternative methods
sqli-labs通关嘿嘿~
Rtsp/onvif protocol easynvr video platform arm version cross compilation process and common error handling
6-8 creating and traversing linked lists
Spring 2021 daily question [week7 not finished]
Winter vacation daily question (improvement group) [end of week 4]
网络安全威胁情报体系
密评-----
Merge K ascending linked lists ---2022/02/26
任意用户密码重置的10种方式
ADB command learning notes
Initial experience of MariaDB spider sharding engine
Acwing game 40 [End]
Line up to pick up the express. At this meeting, I sorted out all kinds of code sets
Speed adjustment of tidb DDL