Shajeel Afzal
Shajeel Afzal

Reputation: 5953

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.

Upvotes: 7

Views: 4051

Answers (2)

Tuhin Karmakar
Tuhin Karmakar

Reputation: 15

Just Use: JSONField in PostgresSQL. That Miraculosly solved the issue. Yesterday, I was facing the same. Solved it via

JSONField in PostgreSQL

Upvotes: 0

s.d
s.d

Reputation: 29436

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);  

Upvotes: 10

Related Questions