如何以编程方式在 Android TextView 中设置 maxLength? [英] How to programmatically set maxLength in Android TextView?
本文介绍了如何以编程方式在 Android TextView 中设置 maxLength?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想以编程方式设置 TextView
的 maxLength
属性,因为我不想在布局中对其进行硬编码.我看不到任何与 maxLength
相关的 set
方法.
I would like to programmatically set maxLength
property of TextView
as I don't want to hard code it in the layout. I can't see any set
method related to maxLength
.
谁能指导我如何做到这一点?
Can anyone guide me how to achieve this?
推荐答案
应该是这样的.但从未将其用于文本视图,仅用于编辑文本:
Should be something like that. but never used it for textview, only edittext :
TextView tv = new TextView(this);
int maxLength = 10;
InputFilter[] fArray = new InputFilter[1];
fArray[0] = new InputFilter.LengthFilter(maxLength);
tv.setFilters(fArray);
这篇关于如何以编程方式在 Android TextView 中设置 maxLength?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文