简体   繁体   English

Android Edittext行和字符限制

[英]Android Edittext line and characterlimitation

For an Assignment I have to implement an App that simplifies SMS writing, eg. 对于作业,我必须实现一个简化SMS编写的应用程序,例如。 for elderly people. 对于老年人。

What im am now trying to do is: 我现在想做的是:

I have an EditText that need to be limited to 5 lines and 255 Characters total. 我有一个EditText,必须限制为5行和255个字符。

Both constraints have to be met. 必须满足这两个约束。 Meaning the person can write 255 of any character but if he/she gets to the end of the 5th Line, no matter how much under 255 characters he/she is, the EditText should not write anything out. 意思是该人可以写255个字符,但是如果他/她到达第5行的末尾,则无论他/她少于255个字符是多少,EditText都不应写任何东西。 Same shoudl happen if he hits 255 characters in the second line. 如果他在第二行中击中255个字符,也会发生同样的情况。

I hope i could make clear what i need. 我希望我能弄清楚我需要什么。

Thanks in advance for any help! 在此先感谢您的帮助!

Ps. PS。 I know simply not responding is a bad practice, but i just want this to work, i will figure out a way to notify the user afterwards by myself. 我知道简单地不响应是一种不好的做法,但是我只是想让它起作用,我将想出一种方法来自己以后通知用户。

You need to put an InputFilter on the EditText and have it allow or disallow the input. 您需要将InputFilter放在EditText ,并允许或禁止输入。 There is already one to limit the total number of characters, you may have to write one yourself to limit based on linecount. 已经有一个限制字符总数的字符,您可能必须写一个限制行数的字符。

See here for more info: Limit text length of EditText in Android 详情请参阅此处: 在Android中限制EditText的文本长度

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

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