Skip to content Skip to sidebar Skip to footer

Android EditText Multiline Does Not Work As It Should

I'm pretty desperate about this feature. I tried pretty much everything there is to find to made these EditTexts multiline enabled, but they just keep going on a single line scroll

Solution 1:

From this comment, the inputType was set in the code as well with:

textMessage.setInputType(InputType.TYPE_TEXT_FLAG_MULTI_LINE |
                         InputType.TYPE_TEXT_FLAG_CAP_SENTENCES);

This is actually not correct, because TYPE_TEXT_FLAG_MULTI_LINE and TYPE_TEXT_FLAG_CAP_SENTENCES are only flags, and do not contain the actual input type. In order for them to work, they must be layered as flags on top of InputType.TYPE_CLASS_TEXT. Without this type class flag, the edit text does not have a base input type class to apply your flags to, and defaults to no specified input type.

So, the correct way to set the input type with both of these flags is:

textMessage.setInputType(InputType.TYPE_CLASS_TEXT |
                         InputType.TYPE_TEXT_FLAG_MULTI_LINE |
                         InputType.TYPE_TEXT_FLAG_CAP_SENTENCES);

For official details on how these flags work, see the Android Developer Docs on InputType and TextView - android:inputType

I'm not sure why the design decision is this. Personally, I think they should have hidden how they are representing their flags (as ints/bit flags), and instead had enums and/or subclasses of InputType for their public interface.


Solution 2:

hey you have to add the following code in xml file ..

android:gravity="top"
android:maxLines="4"
android:inputType="textMultiLine"
android:scrollbars="vertical"
android:textSize="16sp"
android:padding="10dp"

and you have to put activity file ...

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

this is works for me and hope it will works for you .....


Solution 3:

Have you tried using

android:layout_height="wrap content"

instead of

android:layout_height="match_parent"

Post a Comment for "Android EditText Multiline Does Not Work As It Should"