Create a multiline EditText programmatically Create a multiline EditText programmatically android android

Create a multiline EditText programmatically


This should do it

txt.setSingleLine(false);txt.setImeOptions(EditorInfo.IME_FLAG_NO_ENTER_ACTION);


You may also use this:

txt.setInputType(InputType.TYPE_CLASS_TEXT|InputType.TYPE_TEXT_FLAG_MULTI_LINE);


Combining all above answers was the correct answer so here it is:

texInput.setSingleLine(false);texInput.setImeOptions(EditorInfo.IME_FLAG_NO_ENTER_ACTION);texInput.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_MULTI_LINE);texInput.setLines(5);texInput.setMaxLines(10);texInput.setVerticalScrollBarEnabled(true);texInput.setMovementMethod(ScrollingMovementMethod.getInstance());texInput.setScrollBarStyle(View.SCROLLBARS_INSIDE_INSET);