Android Question Add a label to a list

Marc De Loose

Member
Licensed User
Longtime User
I am trying to save a dynamic layout (I can move labels around and then they should get saved in a random access file among other data).

Right now I have this:

B4X:
Sub CreateIdashDisp
  
    Dim maxX As Float = 100%x
    Dim maxY As Float = 100%y
  
    Dim rpmTop As Float = rpmDotGap
    iDashDisp.Clear
  
  
    For i = 1 To MAXIRACINGDATAS
        Dim riDashDispConfig As iDashDispConfig
        riDashDispConfig.ID         = i
        riDashDispConfig.Datas        = Datas(i)
        riDashDispConfig.labeldata    = lblData(i)
        riDashDispConfig.labellabel    = lblLabel(i)
        If i=20 Then
            Dim dfg As Int = 0
        End If
        'riDashDispConfig.MaxX        = maxX
        'riDashDispConfig.MaxY        = maxY
        'riDashDispConfig.rpmTopPos    = rpmTop
        iDashDisp.Add(riDashDispConfig)
    Next
  
    WriteIdashDispListToFile
  
End Sub

Sub WriteIdashDispListToFile
    ' File.DirInternal
    Dim raf As RandomAccessFile
  
    raf.Initialize(File.DirInternal,"iDashDispCOnfig.dat",False)
    raf.WriteObject(iDashDisp,False,0)
    raf.Close
  
  
    Dim iDashDispTest As List
    iDashDispTest.Initialize
    raf.Initialize(File.DirInternal,"iDashDispCOnfig.dat",False)
    iDashDispTest = raf.ReadObject(0)
    raf.Close
  
    Log("File.DirInterna : " & File.DirInternal)
  
End Sub

When i check the "iDashDisp" list before saving in debug I see that all the data is there including the labels.
But when I put a breakpoint after I read the data back to "iDashDispTest" then I see that the "Datas array) is there but all the labels come back as null

"lblData(i) and lbLabel(i) are labels from a label array

Btw the only thing I need is the position,size,colors,text and alignment,etc of the label.

I am probably doing things wrong and I could separate the needed label data differently. But I thought I could just add the label object to the list and be done with it.

Can someone explain why my method does not work and how I can make it work?

Thx a lot
 

DonManfred

Expert
Licensed User
Longtime User
You cannot store/read objectinstances.
Store all the data you need to rebuild the list.
read the data and rebuild the layout.

You should also use writeb4xobject instead of writeobject
 
Upvote 0

Marc De Loose

Member
Licensed User
Longtime User
Ok would be to easy I guess. :)
So I just extract for ex. labellbl(i).Top for example and put that in riDashDispConfig.labellblTop for example. Right?

Thx
 
Upvote 0
Top