本文介绍了进入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十进制值?
发布评论