Android Question Help CSbuilder with editext

Nkalampika

Active Member
Licensed User
hello I created my emoji and I could insert an emoji in an editext! the only problem is that I can not add another emoji! I want this form editext.text = editext.text & emoji help me please
my code :

Private sb As CSBuilder


Sub moj1_Click

sb.Initialize.Size(15).Typeface(Typeface.MONOSPACE)
sb.PopAll


edtext.Text= sb.Image(LoadBitmap(File.DirAssets,"1.png"), 25dip, 25dip, False)

End Sub
 

Mahares

Expert
Licensed User
Longtime User
I could insert an emoji in an editext! the only problem is that I can not add another emoji
You can do it one of 2 ways. You get the same result:
B4X:
Dim cs1 As CSBuilder
    cs1.Initialize.Size(15).Typeface(Typeface.MONOSPACE).Append("Nkalampika").pop. _
    Append("    ").Image(LoadBitmap(File.DirAssets,"1.png"), 25dip, 25dip, False).Append("    "). _
    Image(LoadBitmap(File.DirAssets,"2.png"), 25dip, 25dip, False).popall
    EditText1.Text=cs1

Or you can append 2 CSBuilders to each other:
B4X:
cs1.Initialize.Size(15).Typeface(Typeface.MONOSPACE).Append("Nkalampika").pop. _
    Append("    ").Image(LoadBitmap(File.DirAssets,"1.png"), 25dip, 25dip, False).popall
    Dim cs2 As CSBuilder
    cs2.Initialize.Image(LoadBitmap(File.DirAssets,"2.png"), 25dip, 25dip, False).popall
    Dim cs As CSBuilder
    cs.Initialize.Append(cs1).Append("    ").Append(cs2).PopAll
    EditText1.Text=cs
Please use code tags when you post code. You are not trying hard to help us help you.
 
Upvote 0

Semen Matusovskiy

Well-Known Member
Licensed User
Yes, this sample works, but it's necessary to remember about some moments.

1) CSBulder was integrated to B4A later than other components.
And some functions return string instead of charSequence.

For example, you want to return the text inside EditText.
Theoretically, the following should work
B4X:
Dim charsequence  As CSBuilder
...
charsequence = EditText.Text
But compiler talks:
error: incompatible types: String cannot be converted to SpannableStringBuilder
_s.setObject((android.text.SpannableStringBuilder)(mostCurrent._edittext.getText()));

The workaround:
B4X:
Dim jo                                                                       As JavaObject 
Dim charsequence                                                      As CSBuilder
... 
jo = EditText
charsequence = jo.RunMethod ("getText", Null)

2) Instead of subString it's necessary to use subSequence.
For example,
B4X:
Dim jo                                                                       As JavaObject 
Dim charsequence1                                                    As CSBuilder
Dim charsequence2                                                    As CSBuilder
... 
jo = EditText
charsequence1 = jo.RunMethod ("getText", Null)
jo = charsequence1
charsequence2  = jo.RunMethod ("subSequence", Array (2, 5))

3) If you use "Image", each image is equal to one character in such functions as charsequence.Length, EditText.SelectionStart etc.

4) I found one strange moment relative to images (maybe a bug).
Imagine that we want to output two the same images.

B4X:
Dim b1 As Bitmap
Dim cs As CSBuilder 
Dim cs1 As CSBuilder
...
b1 = LoadBitmap (...)           
cs1.Initialize.Image (b1, 24dip, 24dip, False)
cs.Initialize.Append (cs1).Append (cs1)
EditText.Text = cs

This should work, but does not - instead of second image appears "_".

Meanwhile following works

B4X:
Dim b1 As Bitmap
Dim cs As CSBuilder 
Dim cs1 As CSBuilder
Dim cs2 As CSBuilder
...
b1 = LoadBitmap (...)           
cs1.Initialize.Image (b1, 24dip, 24dip, False)
cs2.Initialize.Image (b1, 24dip, 24dip, False)
cs.Initialize.Append (cs1).Append (cs2)
EditText.Text = cs
 
Upvote 0
Top