androidtextviewspannablestring

Extra line breaks at end of text


I seem to be getting what seems like some extra line breaks after using this method to set the text of a TextView

message.setText(Html.fromHtml( message ));

How can I remove these? They cause my layout to get warped since it adds two extra lines to the output.

The string was saved to my sqlite database via Html.toHtml( editText.getText() ).trim();

Initial string input : hello

Log output of the message variable: <p dir="ltr">hello</p>


Solution

  • Looks like toHtml assumes everything should be in a <p> tag. I'd strip off the beginning and ending <p> and </p> tags before writing to the database.