简体   繁体   English

EditText 的货币格式

[英]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.任何建议将不胜感激。

Library author here.图书馆作者在这里。

We've got a wiki page describing masks for texts with right-to-left alignment;我们有一个wiki 页面,描述了从右到左对齐的文本掩码; this page includes a case similar to yours.此页面包含一个与您类似的案例。

In short, try configuring your listener like this:简而言之,尝试像这样配置你的监听器:

mask.rightToLeft = true

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM