Android Question Save a SpannableString to sql databae


Active Member
Licensed User
Is it possible to save a formatted text (SpannableString) in a Edittext to sql databae.
And retrieve it to a label to edittext as same as it formatted.

If it is not possible then can any put me in a right path to do the following.
01. a page editor upload/save a formatted(bold,size,color) text to mysql database
02. reader view the text as same as the page editor formatted.

Thank you.


Active Member
Licensed User
Not automatically. You will need to save the styling information and later reapply it.
Thanks Erel, I got your idea. But the styling is a JavaObject. So in which field type I can save the styling in Mysql database. In text or int or blob or in any other type.
The Code is below.

Dim Txt as  JavaObject
Txt = SetRTFString("Sample String is here")

SetTextColor(Txt, Colors.Magenta, 0, 5)

    Dim Edittext1 As EditText
    Edittext1.Text = Txt

Sub SetRTFString(AString As String) As JavaObject
    Dim jo As JavaObject
    Return jo.InitializeNewInstance("android.text.SpannableString", Array As Object(AString))
End Sub

Sub SetTextColor(ScanText As JavaObject, AColor As Int, start As Int, ende As Int)
    Dim jo1, jo2 As JavaObject
    jo1 = jo2.InitializeNewInstance("", Array As Object(AColor))
    ScanText.RunMethod("setSpan", Array As Object(jo1, start, ende, 13))
End Sub


Staff member
Licensed User
You can use CSBuilder or RichString to build the styled text:

1. Create a custom type that holds the information that you need to create the style.
2. Add all these type instances to a List and convert it to an array of bytes with B4XSerializator. You can save the bytes in a BLOB field.