获取的EditText的字符数 [英] Getting character count of EditText

查看:88
本文介绍了获取的EditText的字符数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图让一个EditText的字符数。我看了成的EditText TextView的和阶级的不同属性,但似乎没有要返回字符的数量的函数。我曾尝试使用TextWatcher,但因为有时我从preferences载入保存的消息进入的EditText和TextWatcher不计字没有输入正确的话就是不理想。

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 the amount of characters. I have tried to use the TextWatcher, but that is not ideal since sometimes I load a saved message into the EditText from the preferences, and TextWatcher does not count characters not typed right then.

任何帮助将是巨大的!

Any help would be great!

干杯!

推荐答案

只要抓住了的EditText文本作为一个字符串,并检查它的长度:

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

int length = editText.getText().length();

这篇关于获取的EditText的字符数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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