我正在尝试获取 EditText 的字符数.我研究了 EditText 和 TextView 类的不同属性,但似乎没有返回字符数量的函数.我曾尝试使用 TextWatcher,但这并不理想,因为有时我会从首选项中将保存的消息加载到 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.
任何帮助都会很棒!
干杯!
只需将 EditText 中的文本抓取为字符串并检查其长度即可:
Just grab the text in the EditText as a string and check its length:
int length = editText.getText().length();
这篇关于获取 EditText 的字符数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!
如何检测 32 位 int 上的整数溢出?How can I detect integer overflow on 32 bits int?(如何检测 32 位 int 上的整数溢出?)
return 语句之前的局部变量,这有关系吗?Local variables before return statements, does it matter?(return 语句之前的局部变量,这有关系吗?)
如何将整数转换为整数?How to convert Integer to int?(如何将整数转换为整数?)
如何在给定范围内创建一个随机打乱数字的 intHow do I create an int array with randomly shuffled numbers in a given range(如何在给定范围内创建一个随机打乱数字的 int 数组)
java的行为不一致==Inconsistent behavior on java#39;s ==(java的行为不一致==)
为什么 Java 能够将 0xff000000 存储为 int?Why is Java able to store 0xff000000 as an int?(为什么 Java 能够将 0xff000000 存储为 int?)