Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 458
Ton Avatar asked Feb 22 '13 20:02

Ton


People also ask

How to set multiline EditText in android programmatically?

setLayoutParams(lp); txt. setSingleLine(false); txt. setInputType(InputType. TYPE_TEXT_FLAG_MULTI_LINE);

What is multi line text in android Studio?

This tag makes the EditText be at most x many lines tall as specified as value. It accepts an integer value. Note : For multiline EditText by default the cursor and hint text is displayed in the center, you can use android:gravity attribute to set it at top and left of the EditText view : android:gravity="top|left"


2 Answers

This should do it

txt.setSingleLine(false); txt.setImeOptions(EditorInfo.IME_FLAG_NO_ENTER_ACTION); 
like image 180
Daniel López Lacalle Avatar answered Oct 02 '22 13:10

Daniel López Lacalle


You may also use this:

txt.setInputType(InputType.TYPE_CLASS_TEXT|InputType.TYPE_TEXT_FLAG_MULTI_LINE); 
like image 21
waqaslam Avatar answered Oct 02 '22 15:10

waqaslam