measure length of edittext string dynamically in android

佐手、 提交于 2019-12-08 09:07:13

问题


How can i measure length of string entered in the edittext while typing.Because i want to show a warning when the entered text length cross 100 character. Thanks in advance.


回答1:


You can use TextWatcher to your EditText to do that in Android.

Something like this

 EditText test = new EditText(this);
        test.addTextChangedListener(new TextWatcher() {

            public void beforeTextChanged(CharSequence s, int start, int count, int after) {
            }
            public void onTextChanged(CharSequence s, int start, int before, int count) {
                try {
                   //write your code here
                } catch (NumberFormatException e) {
                }
            }
            @Override
            public void afterTextChanged(Editable s) {
                // TODO Auto-generated method stub

            }
        });


来源:https://stackoverflow.com/questions/3665470/measure-length-of-edittext-string-dynamically-in-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!