Android Money Input with fixed decimal

后端 未结 7 1251
鱼传尺愫
鱼传尺愫 2020-12-02 00:07

How do you create an edittext entry that formats input in money format only? When the user enters 5, I want the input to look like \"$0.05\" and when they then enter 3, th

7条回答
  •  臣服心动
    2020-12-02 00:16

    You can use a TextWatcher to do that kind of thing.

    Extend TextWatcher: http://d.android.com/reference/android/text/TextWatcher.html

    public class MyTextWatcher implements TextWatcher {
    
        public void afterTextChanged(Editable arg0) { 
    
        }
    
        public void beforeTextChanged(CharSequence s, int start, int count, int after) { 
    
        }
    
        public void onTextChanged(CharSequence s, int start, int before, int count) {
    
        }
    
    }
    

    Then add it to your editText with

    myEditText.addTextChangedListener(new MyTextWatcher());
    

提交回复
热议问题