3

I have a notebook application and I want to limit my editText maximum lines according to the screen height. for example 40 lines in nexus-6p and 35 lines in nexus5 and etc.

So my question is how can I limit the editText lines? I don't have any idea for this.

UPDATE

I want to create new note page when cursor reached the last line.

FarshidABZ
  • 3,860
  • 4
  • 32
  • 63

5 Answers5

2

I Found the solution, thank everyone for the response.

My solution is:

int lineHeight = getLineHeight();
int height = getHeight();
int maximumLines = height / lineHeight();
FarshidABZ
  • 3,860
  • 4
  • 32
  • 63
0

Check your screen size and put lines acording the height.

Display display = getWindowManager().getDefaultDisplay();
int height = display.getHeight();

//Calculate the lines with the height proportion

edittext.setMaxLines(lines);
Roger RV
  • 132
  • 3
  • 15
0

You can get screen size in pixel by writing following code.

Display display = getWindowManager().getDefaultDisplay();
Point size = new Point();
display.getSize(size);
int width = size.x;
int height = size.y;

After that you can put the condition and then assign the EditText in following way

editText.setMaxLines();

Your problem will be solved

For more details of Screen size refer the link: Supporting Multiple Screens

Pankaj Lilan
  • 4,245
  • 1
  • 29
  • 48
0

I think you should create different layout files based on the screen dimensions. In those layout files you can change the maxLine parameter for the EditText.

Check https://developer.android.com/guide/practices/screens_support.html

jaibatrik
  • 6,770
  • 9
  • 33
  • 62
  • No, exactly I want to set maximum lines, cause I want to create new note page when cursor reached to the last line. Thank you – FarshidABZ Feb 17 '17 at 09:46
0

If your EditText just contains chars, use screenSize/editText.getLineHeight(). However, if it also contains some mark-ups(like Spannable), this method will be useless and there may not be a solution.

Lym Zoy
  • 951
  • 10
  • 16