For Android EditText maxlines=true does not work if digits are applied and single line true is deprecated so anyone has any suggestions?
Asked
Active
Viewed 957 times
-11
-
1you have to give the numbers to set the max lines for your editext. Like set maxLines = "2" . It will work then – Umair Sep 07 '17 at 07:38
-
1maxLines take integer not a boolean varibale so you should use maxLines = "1" – Navin Gupta Sep 07 '17 at 07:41
-
1So... you are telling it `Set the maximum number of lines to... YES`. Does it make sense to you? – Phantômaxx Sep 07 '17 at 07:42
-
Ok so set inputType = "text" and then it should work. – Navin Gupta Sep 07 '17 at 07:53
-
watch this link https://stackoverflow.com/questions/7092961/edittext-maxlines-not-working-user-can-still-input-more-lines-than-set – Navin Gupta Sep 07 '17 at 07:54
3 Answers
2
see this example
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="4dp"
android:digits="1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ"
android:maxLength="15"//used to set max character
android:maxLines="1"/>//used to set max number of lines

Akshay Katariya
- 1,464
- 9
- 20
-
-
1
-
1@Rudee I have checked and its working for me, so before commenting please do some research and try something, check my revised abswer – Akshay Katariya Sep 07 '17 at 08:07
0
Put this code in your activity
editText = (EditText) findViewById(R.id.editText);
editText.setSingleLine(true);
This is how your xml will look
<EditText
android:id="@+id/editText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:digits="abcdefghijklmnopqrstuvwxyz"
android:maxLines="1"
android:textColor="@android:color/black"/>

Akshay Katariya
- 1,464
- 9
- 20

Arjun Solanki
- 236
- 1
- 11
-
1put android:digits="abcdefghijklmnopqrstuvwxyz" and then check maxlines will not work. – Rudee Sep 07 '17 at 08:21
0
I think you didnt specify this parameter:
android:inputType="text"
Without it you can even put new line in edit text. You could add also these attributes:
android:maxLines="1"
android:lines="1"
Though when I checked it without inputType attribute, it still didn't work. Hope I helped

M. Wojcik
- 2,301
- 3
- 23
- 31