Android 简单的 EditText 货币格式化程序
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10297769/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Simple EditText currency formatter
提问by Alin
Possible Duplicate:
Better way to Format Currency Input editText?
可能的重复:
更好的方式来格式化货币输入 editText?
The problem is simple and basic... but I can't find a decent way of handling it. I have some fields with money values and I need to have both the currency symbol and the decimal value. Here is what I am talking about:
问题很简单也很基本......但我找不到处理它的体面方法。我有一些带有货币值的字段,我需要同时具有货币符号和十进制值。这就是我要说的:
The user will input the value: 1 and then . and then 8 and then 0. The EUR symbol I want it to be visible all time.
用户将输入值: 1 然后 。然后是 8,然后是 0。欧元符号我希望它一直可见。
What's the best way of achieving this ?
实现这一目标的最佳方法是什么?
采纳答案by Thkru
Try to use a textwatcher :D
尝试使用文本观察器:D
http://developer.android.com/reference/android/text/TextWatcher.html
http://developer.android.com/reference/android/text/TextWatcher.html
Better way to Format Currency Input editText?
With this u can format the incoming String before its display, so u can easily append a "" and other stuff
有了这个,你可以在显示之前格式化传入的字符串,所以你可以轻松地附加一个“”和其他东西
回答by Renard
You can achieve that by using a TextWatcher. Look at this Questionwhich is quite similar to yours.
您可以通过使用TextWatcher来实现这一点。看看这个问题,它和你的非常相似。