The EditText control of Android prohibits the input of spaces and carriage returns

1. The EditText input box controls that no spaces can be entered. Add an addtextchangedlistener to EditText to listen. If there are spaces, split intercepts and intercepts, and then the for loop rearranges the intercepted string array that does not contain spaces, so that the string does not contain spaces. Finally, rewrite the string to EditText, At this time, there will be a problem that the cursor will automatically jump to the first position. In ontextchanged, there will be a variable called start. It will pass in the cursor position before the space input, and EditText. Setselection (int) will change the specific position of the cursor.

Specific code:

2. EditText control cannot enter carriage return. Add Android: singleline = "true" in XML

The above is the whole content of this article. I hope the content of this article can bring some help to your study or work. At the same time, I also hope to support a lot of 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
分享
二维码
< <上一篇
下一篇>>