测量的EditText字符串长度动态android系统 [英] measure length of edittext string dynamically in android

查看:230
本文介绍了测量的EditText字符串长度动态android系统的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我怎样才能衡量,而typing.Because我想表明,当输入的文本长度跨越100个字符的一个警告的EditText输入的字符串长度。
先谢谢了。

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.

推荐答案

您可以使用 TextWatcher 你的的EditText 要做到这一点在Android中。

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

像这样

 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

            }
        });

这篇关于测量的EditText字符串长度动态android系统的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆