如何设置编辑文本的最小长度? [英] How to set Minimum Length for edit text?

查看:101
本文介绍了如何设置编辑文本的最小长度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在android中设置edittext字段的最小字符长度.使用
设置最大字符数很容易
android:maxLength ="*".

谁能帮我..

how to set the min character length for edittext field in android. it is easy to set the maximum no.of characters length by using

android:maxLength="*".

can anyone please help me..
thanks in advance.

推荐答案

很明显,任何编辑器控件都可以处理最大长度:当您键入Max-1字符并尝试添加一个插入字符时更多,可能会引发异常,并显示错误消息.

现在想象有一个最小约束.您如何想象?假设您将最小值分配给10,则编辑器控件将初始化为0.要使该控件有效,您需要输入10个字符.而且,您会在每次更改时显示错误消息吗?如果您一个接一个地添加字符,则至少需要10次,并且因为在每个这样的步骤上控件仍然无效?直到输入10个字符?我应该继续吗?

由于最小约束非常愚蠢,因此您所要做的就是在将要使用此文本值时对文本进行验证.

—SA
It''s clear how an any editor control can process maximum length: when you typed Max-1 characters and try to add an insert one more, exception could be thrown, error message shown.

Now imagine there is a minimum constrain. How do you imagine it? Let''s say, you assign minimum to 10, editor control is initialized with 0. To make if valid you need to type 10 characters. And what, would you show error message on each change? minimum 10 times if you add characters one-by-one and because on each such step the control remains invalid? Until 10 characters are typed? Should I even continue?

As minimum constraint would be pretty stupid, all you can do is validation of the text at the moment when this text value is about to be used.

—SA


这篇关于如何设置编辑文本的最小长度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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