Create a multiline EditText programmatically

Ton picture Ton · Feb 22, 2013 · Viewed 26.3k times · Source

I am trying to create a multiline EditText by code. This is what I use:

EditText txt = new EditText(this);    
lp = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT, 1.0f);
txt.setLayoutParams(lp);
txt.setSingleLine(false); 
txt.setInputType(InputType.TYPE_TEXT_FLAG_MULTI_LINE);

But it is still in one single line.

Answer

Daniel López Lacalle picture Daniel López Lacalle · May 9, 2013

This should do it

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