Android Question convert ArrayList Java to B4A

Roberto P.

Well-Known Member
Licensed User
I ask for help to convert ArrayList <Byte> Java in B4A

public static void AddRange (ArrayList <Byte> array, byte [] newData)
{
for (int index = 0; index <newData.length; index ++)
{
array.add (newData [index]);
}
}

// function
ArrayList <Byte> commands = new ArrayList <Byte> ();

Byte [] initCommand = new byte [] {0x1b, 0x40}; // Initialization
AddRange (commands, initCommand);

Byte [] slashedZeroCommand = new byte [] {0x1b, 0x2f, 0x00};
if (slashedZero)
{
slashedZeroCommand [2] = 49;
}
else
{
slashedZeroCommand [2] = 48;
}
AddRange (commands, slashedZeroCommand);
......

thank you very much
 

stevel05

Expert
Licensed User
A Java ArrayList is equivelent to a B4a List so the code is literally:
B4X:
Sub Example
    Dim SlashedZero As Boolean            'Whatever that does?


    Dim Commands As List
    Commands.Initialize
 
    Dim initCommand() As Byte = Array As Byte(0x1b,0x40)
    AddRange(Commands,initCommand)
 
    Dim slashedZeroCommand() As Byte = Array As Byte(0x1b,0x2f,0x00)
 
    If SlashedZero Then
        slashedZeroCommand(2) = 49
    Else
        slashedZeroCommand(2) = 48
    End If
 
    AddRange(Commands,slashedZeroCommand)
 
    'Just output the result
    For i = 0 To Commands.Size - 1
        Log(Commands.Get(i))
    Next

End Sub


Sub AddRange(A As List,newData() As Byte)
    For i = 0 To newData.Length -1
        A.Add(newData(i))
    Next
End Sub
 

Roberto P.

Well-Known Member
Licensed User
very kind thank you very much. Stevel
 
Top