进入EDITTEXT十进制值?

编程入门 行业动态 更新时间:2024-10-26 10:30:21
本文介绍了进入EDITTEXT十进制值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有一个编辑文本。我想在它进入十进制值。

I have a edit text. i want to enter the decimal values in it.

这是当我有输入第一个数字。它应该是这样的:0.01

that is when i have enter a first number. it should be like this: .01

然后我有输入第二个数字。它应该是这样的:0.12

then i have enter a second number. it should be like this: .12

然后第三个。它应该是这样的:1.23

then for third one. it should be like this: 1.23

它会是这样的....如何实施此方案。任何想法?

it will go like this.... how to implement this scenario. Any Idea?

推荐答案

您应该在TextWatcher添加到的EditText。当文本改变了这种会通知您。

You should add a TextWatcher to the EditText. This will notify you when the text changes.

当你知道文本已更改,则可以通过一个DecimalFormat运行它:

When you know the text has changed, you can run it through a DecimalFormat:

DecimalFormat decimalFormat = new DecimalFormat(); decimalFormat.setDecimalSeparatorAlwaysShown(true); decimalFormat.setMaximumFractionDigits(2);

更多推荐

进入EDITTEXT十进制值?

本文发布于:2023-10-09 10:33:18,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1475498.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:EDITTEXT   十进制值

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!