問題描述
我有一個帶有 "text = 0.00"
的 EditText
.當我按數字 3 時,它應該是 0.03
,當我第二次按數字 5 時,文本應該是 0.35
.還有35.0
、35.09
這樣的.EditText
最初的值為 0.00
.
I have an EditText
with "text = 0.00"
. When I press the number 3, it should be like 0.03
and the second time when I press the number 5, the text should be 0.35
. And 35.0
, 35.09
like this. The EditText
initially has the value of 0.00
.
這些都是用相同的EditText
完成的.
These are all done with the same EditText
.
我如何實現這一目標?我嘗試將 addTextChangedListener()
與 TextWatcher()
一起使用.
How do I achieve this? I have tried using addTextChangedListener()
with TextWatcher()
.
推薦答案
你選擇了正確的方法.您必須使用 TextWatcher 擴展類并覆蓋 afterTextChanged()
、beforeTextChanged()
、onTextChanged()
.
You have selected correct approach. You have to extend the class with TextWatcher and override afterTextChanged()
,beforeTextChanged()
, onTextChanged()
.
你必須在 afterTextChanged()
方法中編寫你想要的邏輯來實現你需要的功能.
You have to write your desired logic in afterTextChanged()
method to achieve functionality needed by you.
這篇關于按下數字時如何使用 EditText onTextChanged 事件?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!