Chicken Pro
Chicken Pro

Reputation: 86

How to get text of each lines in editText in android?

I try to render text to my canvas like in EditText render .

I found that sum of width of text in each line(display in EditText) may be greater or smaller than line width (getLineWidth) . I don't know why ?

=> I can't break line exactly like in EditText (100%) . How can i do that ?

Upvotes: 1

Views: 1096

Answers (2)

thundertrick
thundertrick

Reputation: 1674

You can get the string value of each line. Then calculate the width.

String[] multiLines = stringFromEditText.split("\n");

// Get each line
String line0 = multiLines[0];
String line1 = multiLines[1];
String line2 = multiLines[2];

// Then get length of each line by str.length() or sth like that

Upvotes: 0

user2471325
user2471325

Reputation:

try fill_parent or wrap_content as per your need.

Upvotes: 1

Related Questions