0

I save my formatted edit text in sqlite database in html then after retrieving it two extra lines are added to the edit text

So I started like so:-

 edt.setText(Html.fromHtml("<b>"+myString+"</b>"));//making it bold
 Editable e = edt.getText();//convert to Editable
 String text = Html.toHtml(e);//convert to String

Then after I inserted text into the database .I retrieved it back to edt this way:-

Spanned sp = Html.fromHtml(text);//convert text to spanned
edt.setText(sp);//setting to the edittext

It was retrieved successfully however 2 extra lines where added to edt at the end of text each time why you think that occurs?.

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
Omar Boshra
  • 447
  • 7
  • 21

2 Answers2

0

try this

edt.setText(Html.fromHtml("<b>"+myString+"</b>"));//making it bold
Editable e = edt.getText();//convert to Editable
/* String text = Html.toHtml(e);//convert to String

Spanned sp = Html.fromHtml(text);  //convert text to spanned */
edt.setText(e);//setting to the edittext
배준모
  • 591
  • 5
  • 12
0

I finally found a solution using code from an answer in this question Remove extra line breaks after Html.fromHtml() .Its all about removing extra html whitspaces but using it for spannable String like so :-

Spanned sp = Html.fromHtml(subnote);

int h = sp.length();

// loop back to the first non-whitespace character

while(--h >= 0 && Character.isWhitespace(sp.charAt(h))) {
}

sp= (Spanned) sp.subSequence(0, h+1);



edt.setText(sp);
Omar Boshra
  • 447
  • 7
  • 21