Search code examples
androidandroid-edittextmultiline

Create a multiline EditText programmatically


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.


Solution

  • This should do it

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