0

I have an editText I made in a TableLayout, I want it to have 5 lines but if I press enter a bunch of times it'll expand the editText box on the screen. I can't figure out how to get this to stop.

LayoutParams bigedit = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT); //width height
bigedit.weight=1;
bigedit.setMargins(10, 0, 0, 10);//Left Top Right Bottom

EditText testEdit1= new EditText(this);
testEdit1.setBackgroundResource(R.drawable.black_rect_border);
testEdit1.setInputType(InputType.TYPE_TEXT_FLAG_MULTI_LINE);
testEdit1.setLines(5);
testEdit1.setMaxLines(5);
testEdit1.setVerticalScrollBarEnabled(true);
testEdit1.setId(unusedid);
testEdit1.setSingleLine(false);
testEdit1.setGravity(Gravity.TOP|Gravity.LEFT);
unusedid++;
testEdit1.setTextSize(16);
testEdit1.setLayoutParams(bigedit);

row1.addView(testEdit1);
tl.addView(row1);

Where tl is the TableLayout in the activity.

user2312638
  • 423
  • 1
  • 6
  • 17

3 Answers3

0

See the code provided in one of the answers to this question, which might help you out.

Community
  • 1
  • 1
Anthony Atkinson
  • 2,841
  • 3
  • 16
  • 22
  • I even put in MaxLines and it still expands the boundaries rather than keeping it set and having a scroll wheel (which is acceptable in my case) – user2312638 Oct 08 '13 at 20:14
  • It's not the *accepted* answer to the linked question but the one underneath with the longer code sample that I figured may help you out. – Anthony Atkinson Oct 08 '13 at 20:49
0

Just guessing, but according to setSingleLine docs.-

setSingleLine(boolean singleLine) If true, sets the properties of this field (lines, horizontally scrolling, transformation method) to be for a single-line input; if false, restores these to the default conditions.

This line.-

testEdit1.setSingleLine(false);

could be overriding your maxLines setting. Just try and remove that line, there's no need for it, anyway.

ssantos
  • 15,228
  • 7
  • 46
  • 70
0

Well I got it to work (except the vertical scroll bar), oddly by changing the order of those statements.

EditText testEdit1= new EditText(this);
testEdit1.setVerticalScrollBarEnabled(true);
testEdit1.setBackgroundResource(R.drawable.black_rect_border);
testEdit1.setInputType(InputType.TYPE_TEXT_FLAG_MULTI_LINE);    
testEdit1.setLines(5);
testEdit1.setSingleLine(false);
testEdit1.setMaxLines(5);
testEdit1.setGravity(Gravity.TOP|Gravity.LEFT);
testEdit1.setId(unusedid);
unusedid++;
testEdit1.setTextSize(16);
testEdit1.setLayoutParams(bigedit);

Apparently the setinput line only works if you set the class to type text using

testEdit1.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_MULTI_LINE);
user2312638
  • 423
  • 1
  • 6
  • 17