简体   繁体   English

如何在Android中获取textView的最大长度?

[英]How can I get the maximum length of a textView in Android?

Hello I created a textview in the main layout, with a certain value for android:maxLength. 您好,我在主布局中创建了一个textview,并为android:maxLength提供了一定的值。 Now I'd like to get that value back into an int variable; 现在,我想将该值返回一个int变量; I know how to refer to the textView in Java, but there are no direct methods in the TextView Object to get its maximium length. 我知道如何在Java中引用textView,但是TextView Object中没有直接方法来获取其最大长度。 Is there any way to obtain this value? 有什么方法可以获取此值?

Unfortunately, you can't. 不幸的是,你不能。 When you set maximum length what actually happens is that a new InputFilter.LengthFilter is created and added to input filters of this field. 设置最大长度时,实际发生的情况是创建了一个新的InputFilter.LengthFilter并将其添加到此字段的输入过滤器中。 You can retrieve all the filters of this TextView , but even if you find this particular filter, you can't find out what was the maximum size. 您可以检索此TextView所有过滤器,但是即使找到此特定过滤器,也无法找出最大大小。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM