Android Question file.writelist with Type defined variables

Rusty

Well-Known Member
Licensed User
Longtime User
I have created a list of type defined variables:
B4X:
Type prtmap(Name As String, URL As String, BitmapName As String)
Public PrinterList As List
...

  PrinterList.Initialize
  Dim NewPrinter1, NewPrinter2,NewPrinter3,NewPrinter4,NewPrinter4, _
   NewPrinter5, NewPrinter6,NewPrinter7,NewPrinter8 As prtmap
  NewPrinter1.Initialize
  NewPrinter1.Name =  "Samsung Print Service Plugin"
  NewPrinter1.URL =  $"https://play.google.com/store/apps/details?id=com.sec.app.samsungprintservice&rdid=com.sec.app.samsungprintservice"$
  NewPrinter1.BitmapName = "samsungprintservicepluginlogo.png"
  PrinterList.Add(NewPrinter1)
  NewPrinter2.Name =  "HP Print Service Plugin"
  NewPrinter2.URL =  $"https://play.google.com/store/apps/details?id=com.hp.android.printservice&rdid=com.hp.android.printservice"$
  NewPrinter2.BitmapName = "HPPrintServicePluginlogo.png"
  PrinterList.Add(NewPrinter2)
… 'I write the list to a file

 File.WriteList(Starter.ConfigUser.Folder, Starter.ConfigUser.FileName, PrinterList)

… 'Then I read it

  PrinterList = File.ReadList(Starter.ConfigUser.Folder, Starter.ConfigUser.FileName)

… ' then I parse the list
  Dim FindApp as prtmap
  For k = 0 To PrinterList.Size - 1
   FindApp = PrinterList.Get(k)
   Log("FIND APP   " & FindApp.Name)  '<---<<< the list does not restore the Typed variables
                                                         ' the .NAME and all others within the Type are not defined
  Next

The DATA looks like this:
(ArrayList) [[BitmapName=samsungprintservicepluginlogo.png, IsInitialized=true, Name=Samsung Print Service Plugin, , URL=[URL]https://play.google.com/store/apps/details?id=com.sec.app.samsungprintservice&rdid=com.sec.app.samsungprintservice[/URL]], [BitmapName=HPPrintServicePluginlogo.png, IsInitialized=false, Name=HP Print Service Plugin, , URL=[URL]https://play.google.com/store/apps/details?id=com.hp.android.printservice&rdid=com.hp.android.printservice[/URL]], [BitmapName=CanonPrintInkjetSELPHYlogo.png, IsInitialized=false, Name=Canon Print Inkjet/SELPHY, , URL=[URL]https://play.google.com/store/apps/details?id=jp.co.canon.bsd.ad.pixmaprint[/URL]], [BitmapName=canonprintservicelogo.png, IsInitialized=false, Name=Canon, , URL=[URL]https://play.google.com/store/apps/details?id=jp.co.canon.android.printservice.plugin[/URL]], [BitmapName=dynamixlogo.png, IsInitialized=false, Name=Dynamix, , URL=[URL]https://play.google.com/store/apps/details?id=com.dynamixsoftware.printershare[/URL]], [BitmapName=brotherprintservicepluginlogo.png, IsInitialized=false, Name=Brother, , URL=[URL]https://play.google.com/store/apps/details?id=com.brother.mfc.brprint[/URL]], [BitmapName=epsoniprintlogo.png, IsInitialized=false, Name=Epson, , URL=[URL]https://play.google.com/store/apps/details?id=epson.print[/URL]], [BitmapName=Printer.png, IsInitialized=false, Name=Pick One, , URL=[URL]https://play.google.com/store/search?q=print%20service%20plugin&c=apps[/URL]]]

How do I get the above data loaded back into the PrinterList?
Thanks,
Rusty
 

DonManfred

Expert
Licensed User
Longtime User
Upvote 0

Rusty

Well-Known Member
Licensed User
Longtime User
Thanks Don.
For anyone seeking an answer, this works easily and well:
B4X:
Sub WriteConfig
    PrinterConfig.Initialize(Starter.ConfigUser.Folder, Starter.ConfigUser.FileName, False)
    PrinterConfig.WriteObject(PrinterList, True, PrinterConfig.CurrentPosition)
    PrinterConfig.Close
End Sub

Sub ReadConfig
    If File.Exists(Starter.ConfigUser.Folder, Starter.ConfigUser.FileName) Then    
        PrinterConfig.Initialize(Starter.ConfigUser.Folder, Starter.ConfigUser.FileName, False)
        PrinterList = PrinterConfig.ReadObject(0)
        PrinterConfig.close
    End If
End Sub
 
Upvote 0
Top