Android Question CharSequence vs. CSBuilder in parameters?

Dave O

Active Member
Licensed User
If we want to include support for CharSequence in our classes and libraries, should we be changing external-facing String parameters (and any related internal ones) to CSBuilder?

(If I understand correctly, we can't reference CharSequence directly.)
 

Semen Matusovskiy

Well-Known Member
Licensed User
As I understand, we can replace String to CharSequence as parameters in own library without changing other code.

CharSequence is an interface, not a concrete class. And implemented in a lot of classes (including String)
AlteredCharSequence, CharBuffer, Editable, GetChars, PrecomputedText, Spannable, SpannableString, SpannableStringBuilder (CSBuilder), Spanned, SpannedString, String, StringBuffer, StringBuilder

Small sample. In java code input and output parameters declared as CharSequence.
We can use strings as input-output (first call).
We can use CSBuilder or another classes as input-output (second call).

B4X:
Sub Activity_Resume

    Dim jo As JavaObject
    jo.InitializeContext

    Dim strInput1 As String = "Test for String"   
    Dim strOutput1 As String = jo.RunMethod ("test", Array (strInput1))
    Log (strOutput1)

    Dim strInput2 As CSBuilder
    strInput2.Initialize.Append ("Test for CSBuilder")
    Dim strOutput2 As CSBuilder
    strOutput2.Initialize.Append (jo.RunMethod ("test", Array (strInput2)))
    Log (strOutput2)

End Sub

#If Java

import java.lang.CharSequence;

public CharSequence test (CharSequence parameter) {
   return parameter.toString () + " *** Added by test";
}
#End If
 
Last edited:

Erel

Administrator
Staff member
Licensed User
If we want to include support for CharSequence in our classes and libraries, should we be changing external-facing String parameters (and any related internal ones) to CSBuilder?
You should use Object.

Example from xCustomListView:
B4X:
Public Sub AddTextItem(Text As Object, Value As Object)
 

Dave O

Active Member
Licensed User
You should use Object.

Example from xCustomListView:
B4X:
Public Sub AddTextItem(Text As Object, Value As Object)
Thanks. So, in the depths of my class, when I need to do something with the argument, I'll need to cast it to csBuilder?
 
Top