当前位置:网站首页>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
边栏推荐
- 6-8 creating and traversing linked lists
- Kubernetes deploys elk and collects container logs using filebeat
- Class question: how to ensure that line table storage can be inserted at any time?
- Chorus translation
- TiDB-unsafe recover(tikv宕机数大于等于一半副本数)
- Network Security Threat Intelligence System
- Simple understanding of events
- Threejs uses indexeddb cache to load GLB model
- 送给大模型的「高考」卷:442人联名论文给大模型提出204个任务,谷歌领衔
- [pat grade B question bank] complete summary
猜你喜欢

Tle6389-2g V50's unique pwm/pfm control scheme has a duty cycle of up to 100%, forming a very low differential pressure - keshijin mall

mariadb spider分片引擎初体验

【C】 Compilation preprocessing and environment

Merge K ascending linked lists ---2022/02/26

Service learning notes 01 start method and life cycle

Service learning notes 02- actual combat startservice and bindservice
![[collect first and use it sooner or later] 49 Flink high-frequency interview questions series (I)](/img/c4/eb57b29700b6c033f6d0af2892f7a6.png)
[collect first and use it sooner or later] 49 Flink high-frequency interview questions series (I)

Kubernetes deploys elk and collects container logs using filebeat
![[foundation of deep learning] learning of neural network (3)](/img/a5/1b80ba85faf8fa636b784c76d4df2f.png)
[foundation of deep learning] learning of neural network (3)

ADB command learning notes
随机推荐
Nocturnal installs APK and BP agent
6-8 reading and writing of structured files 1
Chorus翻译
简单理解事件
[collect first and use it sooner or later] 49 Flink high-frequency interview questions series (I)
Hello go (XII). Go language common standard library II
Codeworks round 479 (Div. 3) [done]
The tle6389 step-down DC-DC switch controller has high efficiency in the whole load range of 1mA to 2.5A - keshijin mall
Simple understanding of events
Tidb CDC log tables are not eligible to replicate
Secret comment-----
【C】 ATOI function implementation +offsetof implementation + exchange binary odd and even digits
Learning about canvas API
Hello go (XIV). Go language common standard library IV
Valid parentheses ---2022/02/23
网络安全威胁情报体系
SQL报错注入1
送给大模型的「高考」卷:442人联名论文给大模型提出204个任务,谷歌领衔
After class, I looked at the document and went back to the lab. I picked up the forgotten SQL operators again
【先收藏,早晚用得到】49个Flink高频面试题系列(二)