[英]Currency format for EditText
I am using this library to format the text as user is typing.我正在使用这个库来格式化用户正在输入的文本。 I have an EditText
where user types in money.我有一个EditText
,用户可以在其中输入钱。 I want to achieve the following behavior as user types:我想在用户类型中实现以下行为:
User input -> Result in EditText
用户输入 -> EditText
结果
1 -> 1 dollars 1 -> 1 美元
10 -> 10 dollars 10 -> 10 美元
100 -> 100 dollars 100 -> 100 美元
1000 -> 1 000 dollars 1000 -> 1 000 美元
However, what I got is that:然而,我得到的是:
1 -> 1 dollars 1 -> 1 美元
10 -> 10 dollars 10 -> 10 美元
100 -> 100 dollars 100 -> 100 美元
1000 -> 100 0 dollars 1000 -> 100 0 美元
val mask = MaskedTextChangedListener(
"[000] [000] [000] dollars",
false,
etAmount,
object : TextWatcher {
override fun afterTextChanged(s: Editable?) { }
override fun beforeTextChanged(s: CharSequence?, start: Int, count: Int, after: Int) {}
override fun onTextChanged(s: CharSequence?, start: Int, before: Int, count: Int) {}
},
null
)
etAmount.addTextChangedListener(mask)
The documentation is not very clear on how to achieve this and I am stuck on this issue.文档对如何实现这一点不是很清楚,我被困在这个问题上。 Any suggestions would be greatly appreciated.任何建议将不胜感激。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.