Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Save/Retrieve the "Rich Formatted Text" in the database without losing its Format

I am using commonsguy / cwac-richedit Library for Rich Text Editing. After doing so i am saving the formatted text in the database. But when i retrieve the saved formatted string its formatting is removed.

I want to know that how to save/retrieve the text from the database without losing format.

like image 833
Shajeel Afzal Avatar asked Jun 17 '13 05:06

Shajeel Afzal


1 Answers

EditText uses HTML markup (limited set). Key Interfaces for this type of markup text being Spanned and Spannable.

EditText uses Editable to represent text, which implements Spannable.

Html class is provided for conversions between markup and Spanned text, you can use it as well:

    //--suppose this is typed to an EditText called et --
    Spanned s = Html.fromHtml("<i>Hi</i> There ! <b>how're you ?</b>");
    et.setText(s);

    //--save to string--
    Editable e = et.getText();
    String s2 = Html.toHtml(e);

    //--restore from string--
    Spanned s3 = Html.fromHtml(s2);
    et.setText(s3);  
like image 109
S.D. Avatar answered Sep 24 '22 06:09

S.D.