Live editing of users input

后端 未结 6 1241
半阙折子戏
半阙折子戏 2020-11-27 07:37

Is it possible to auto insert characters into an EditText as the user inputs data?

I.e. if the user is entering a long number such as <

6条回答
  •  孤街浪徒
    2020-11-27 08:03

    @Override
    public void afterTextChanged(Editable s) {
    
        if(s.length() == 3 && len < s.length()){
            s.append(" - ");
        }
    
    }
    
    @Override
    public void beforeTextChanged(CharSequence s, int start, int count,
            int after) {
        len = s.length();
    }
    

    This will do as well, only this code will insert " - " after 3rd character.

提交回复
热议问题