2

This is my Edittext's xml code

        <EditText
        android:id="@+id/meeting_who_was_txt"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:paddingLeft="15dp"
        android:gravity="top"
        android:scrollbars="vertical"
        android:layout_marginTop="5dp"
        android:paddingRight="15dp"
        android:inputType="textMultiLine"
        android:maxLines="2"/>

This is java code

  meetingWhoWas=(EditText)findViewById(R.id.meeting_who_was_txt);
  meetingWhoWas.setMovementMethod(new ScrollingMovementMethod());

when i run my app,multiLine working perfect in Edittext,but maxlines not working. What is a wrong in my code and how i can solve my problem?

BekaKK
  • 2,173
  • 6
  • 42
  • 80
  • See this: http://stackoverflow.com/questions/7092961/edittext-maxlines-not-working-user-can-still-input-more-lines-than-set – rafsanahmad007 Mar 27 '17 at 19:53

2 Answers2

1

You just need to make sure you have the attribute "inputType" set. It doesn't work without this line.

android:inputType="text"

Islam Ahmed
  • 668
  • 9
  • 19
-1

See the Documentation

  1. Attribute android:inputType="textMultiLine" allows multiple lines of text in the EditText field. If this flag is not set, the EditText field will be constrained to a single line.

  2. Attribute android:maxLines="2" represensts the height of EditText. It makes EditText be at most two lines tall.

For single line EditText use:

<EditText
    android:id="@+id/meeting_who_was_txt"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:inputType="text"
    android:maxLines="1"/>

For multiple line EditText use:

<EditText
    android:id="@+id/meeting_who_was_txt"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:inputType="textMultiLine"
    android:maxLines="2"/>

Hope this will help~

Ferdous Ahamed
  • 21,438
  • 5
  • 52
  • 61