dei*_*988 2 android limit maxlength android-edittext
I know that I can set the maximum length of an input text within an EditText by using
android:maxLength="10".
Run Code Online (Sandbox Code Playgroud)
But can I also set the maximum length so that once the entire EditText is filled with text, the user can't type in anything anymore?
Something like this:
|_________________________| <-- empty EditText
|texttexttexttext_________| <-- user can still type in text
|texttexttexttexttexttextt| <-- that's it, user can't type in stuff anymore
Run Code Online (Sandbox Code Playgroud)
How could I accomplish that?
EDIT: In other words: I don't want it limited to exactly 10 characters, but I want to limit it so that once the entire EditText is filled (which depends on the screen size), the user can't type in stuff anymore.
小智 5
Java代码
EditText edittext;
edittext.setFilters(new InputFilter[]{new InputFilter.LengthFilter(20)});
Run Code Online (Sandbox Code Playgroud)
XML格式
<EditText
android:maxLength="10"
/>
Run Code Online (Sandbox Code Playgroud)