Getting character count of EditText

后端 未结 3 493
傲寒
傲寒 2021-01-11 11:50

I\'m trying to get a character count of an EditText. I\'ve looked into different properties of the EditText and TextView classes, but there doesn\'t seem to be a function th

相关标签:
3条回答
  • 2021-01-11 12:28

    In Kotlin it's very easy

    <EditText_name>.Text.length

    0 讨论(0)
  • 2021-01-11 12:29

    Just grab the text in the EditText as a string and check its length:

    int length = editText.getText().length();
    
    0 讨论(0)
  • 2021-01-11 12:37
    EditText edittext;
    private final TextWatcher mTextEditorWatcher = new TextWatcher() {
    
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {
    
            }
    
            public void onTextChanged(CharSequence s, int start, int before, int count) {
               //This sets a textview to the current length
               textview.setText(String.valueOf(s.length());
            }
    
            public void afterTextChanged(Editable s) {
            }
    };
     editText.addTextChangedListener(mTextEditorWatcher);
    
    0 讨论(0)
提交回复
热议问题