开发者

measure length of edittext string dynamically in android

开发者 https://www.devze.com 2023-01-15 00:56 出处:网络
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 charact开发者_开发问答er.

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 charact开发者_开发问答er. Thanks in advance.


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

            }
        });
0

精彩评论

暂无评论...
验证码 换一张
取 消