Getting Character Count Of Edittext
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 that returns
Solution 1:
Just grab the text in the EditText as a string and check its length:
intlength = editText.getText().length();
Solution 2:
EditText edittext;
privatefinalTextWatchermTextEditorWatcher=newTextWatcher() {
publicvoidbeforeTextChanged(CharSequence s, int start, int count, int after) {
}
publicvoidonTextChanged(CharSequence s, int start, int before, int count) {
//This sets a textview to the current length
textview.setText(String.valueOf(s.length());
}
publicvoidafterTextChanged(Editable s) {
}
};
editText.addTextChangedListener(mTextEditorWatcher);
Post a Comment for "Getting Character Count Of Edittext"