EditText in Android prohibits the input of expression instance code

In a recent project, users do not want to input expressions when editing data. If users input expressions, an error will be reported when uploading them to the background, so we need to make a judgment at the front end. Let's talk about how to shield expressions in EditText.

There are many such columns on the Internet, but they will fall into the pit accidentally. For example, inherit EditText and rewrite the addtextchangedlistener () method. Maybe there were no problems when you tested, but there will be many problems after the project goes online. The error rate is very high, but when you check the background of Youmeng, it seems to be an error in intercepting the length of the string. So I suggest you don't use that method.

Because the above method doesn't work, we must think of other solutions. Here, we think of intercepting the characters entered by the user through the filter, which can avoid the problem of intercepting the character string corner mark out of bounds.

Then set the filter for EditText. Here, two filters are set for EditText. The first one is to mask the expression, and the second one is to set the limit of how many words the user can input

Of course, the last thing to remind you here is that such shielded emoticons cannot be completely shielded. So in the end, we can only choose to let users fill in English, Chinese characters and numbers. The following is the filtered code

OK, that's it. I hope it will help you in your study, and I also hope you can support programming tips.

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>