B4J Question Problem updating TableView

DonManfred

Expert
Licensed User
Longtime User
Hello, i have problems updating a TableView

NOTE that i did not used B4J much till now. But for the tool i want to write i need to do it with B4J as it need to run on Windows; not B4A

Please be patience ;-)

tv_031.png


The Initial list is done with this code

B4X:
    For o = 0 To driverlist.Size-1
        Dim driver As RaceDriver = driverlist.Get(o)
        '0 Pos
        '1 Fahrer
        '2 Team
        '3 Grid
        '4 Stopps
        '5 BestLap
        '6 Sektor1
        '7 Sektor2
        '8 PKT
        Dim lblPos, lblPlusMinus, lblFahrer, lblTeam, lblGrid, lblStops, lblBestLap, lblSektor1, lblSektor2, lblPKT As Label

        lblPos.Initialize("")
        lblPos.Text = driver.pos
        lblPos.Font = fx.DefaultFont(12)
        lblPos.TextColor = fx.Colors.Black
      
        Dim verbesserung As Int = 0
        Dim gridpos As Int = driver.pos
        If o=gridpos Then
            verbesserung = 0
        else if o > gridpos Then
            verbesserung = gridpos-o
        else if o < gridpos Then
            verbesserung = gridpos-o
        End If
        lblPlusMinus.Initialize("")
        lblPlusMinus.Font = fx.CreateFontAwesome(12)
        If driver.pos < driver.Grid Then
            lblPlusMinus.TextColor = fx.Colors.Green
            'lblPlusMinus.Style = $"-fx-background-image: url(${File.GetUri(File.DirAssets, "up.png")});"$
        Else If driver.pos > driver.Grid Then
            lblPlusMinus.TextColor = fx.Colors.Red
            'lblPlusMinus.Style = $" -fx-background-image: url(${File.GetUri(File.DirAssets, "down.png")});"$
        End If
        If verbesserung > 0 Then
            lblPlusMinus.Text = "+"&verbesserung
        Else
            lblPlusMinus.Text = verbesserung
        End If
      
        Dim color As String
        If o Mod 2 = 0 Then color = "palegreen" Else color = "skyblue"
        lblPos.Style = "-fx-background-color: " & color & ";"

        lblFahrer.Initialize("")
        lblFahrer.Text = driver.Driver
        lblFahrer.Font = fx.DefaultFont(12)
        lblFahrer.TextColor = fx.Colors.Blue
      
        lblTeam.Initialize("")
        lblTeam.Text = driver.Team
        lblTeam.Font = fx.DefaultFont(12)
        lblTeam.TextColor = fx.Colors.Green
      
        lblGrid.Initialize("")
        lblGrid.Text = driver.Grid
        lblGrid.Font = fx.DefaultFont(12)
        lblGrid.TextColor = fx.Colors.Black
      
        lblStops.Initialize("")
        lblStops.Text = driver.stopps
        lblStops.Font = fx.DefaultFont(12)
        lblStops.TextColor = fx.Colors.Black
      
        lblBestLap.Initialize("")
        lblBestLap.Text = driver.BestLap
        lblBestLap.Font = fx.DefaultFont(12)
        lblBestLap.TextColor = fx.Colors.Magenta
      
        lblSektor1.Initialize("")
        lblSektor1.Text = driver.Sector1Time
        lblSektor1.Font = fx.DefaultFont(12)
        lblSektor1.TextColor = fx.Colors.Yellow
      
        lblSektor2.Initialize("")
        lblSektor2.Text = driver.Sector2Time
        lblSektor2.Font = fx.DefaultFont(12)
        lblSektor2.TextColor = fx.Colors.Black
      
        lblPKT.Initialize("")
        lblPKT.Text = driver.Punkte
        lblPKT.Font = fx.DefaultFont(12)
        lblPKT.TextColor = fx.Colors.Black
        rd.GetTable.Items.Set(o,Array As Object(WrapLabel(lblPos, "CENTER"), WrapLabel(lblPlusMinus, "CENTER"), WrapLabel(lblFahrer, "CENTER_LEFT"), WrapLabel(lblTeam, "CENTER_LEFT"), WrapLabel(lblGrid, "CENTER_LEFT"), WrapLabel(lblStops, "CENTER_LEFT"), WrapLabel(lblBestLap, "CENTER_LEFT"), WrapLabel(lblSektor1, "CENTER_LEFT"), WrapLabel(lblSektor2, "CENTER_LEFT"), WrapLabel(lblPKT, "CENTER_LEFT")))
        'rd.GetTable.Items.Set(o,Array As Object(WrapLabel(lblPos, "CENTER"), WrapLabel(lblFahrer, "CENTER LEFT"), WrapLabel(lblTeam, "CENTER LEFT"), WrapLabel(lblGrid, "CENTER LEFT"), WrapLabel(lblStops, "CENTER LEFT"), WrapLabel(lblBestLap, "CENTER LEFT"), WrapLabel(lblSektor1, "CENTER LEFT"), WrapLabel(lblSektor2, "CENTER LEFT"), WrapLabel(lblPKT, "CENTER LEFT")))
        'rd.GetTable.Items.Set(i,driver)

    Next

where WrapLabel is this code i found in the Forum:
B4X:
Sub WrapLabel(lbl As Label, Alignment As String) As Pane
    Dim pn1 As AnchorPane
    pn1.Initialize("")
    pn1.AddNode(lbl, 0, 0, -1, -1)
    pn1.FillHorizontally(lbl, 0, 0)
    Dim jo1 = lbl As JavaObject
    jo1.RunMethod("setAlignment", Array As Object(Alignment))
    Return pn1
End Sub

Problem:
After filling the Table with the 20 rows (max) i need to Update all the Rows and Columns twice a second.

If i use this code directly after creating the Table
B4X:
    Dim objarr() As Object = rd.GetTable.Items.Get(0)
    Log("RaceData #"&o&" Content: "&objarr)
    Log("ContentLength: "&objarr.Length)
    Log(GetType(objarr(0)))
    Log(GetType(objarr(1)))
    Log(GetType(objarr(2)))
    Log(GetType(objarr(3)))

I get the expected results. The reference to the anchorpane

RaceData Table Size 20
RaceData #0 Content: [Ljava.lang.Object;@1fc1da7
ContentLength: 10
javafx.scene.layout.AnchorPane
javafx.scene.layout.AnchorPane
javafx.scene.layout.AnchorPane
javafx.scene.layout.AnchorPane

but when i run the app and i get new data which i want to put into the 20 Table rows i do not get the AnchorPanes

RaceData #0 Content: [Ljava.lang.Object;@d9d7aa
ContentLength: 9
java.lang.Integer
java.lang.String
java.lang.String
java.lang.Integer
RaceData Table Size 20
RaceData #1 Content: [Ljava.lang.Object;@1bcf171
ContentLength: 9
java.lang.Integer
java.lang.String
java.lang.String
java.lang.Integer
RaceData Table Size 20
RaceData #2 Content: [Ljava.lang.Object;@1b4cb4e
ContentLength: 9
java.lang.Integer
java.lang.String
java.lang.String
java.lang.Integer
RaceData Table Size 20
RaceData #3 Content: [Ljava.lang.Object;@15f4047
ContentLength: 9
java.lang.Integer
java.lang.String
java.lang.String
java.lang.Integer
RaceData Table Size 20
RaceData #4 Content: [Ljava.lang.Object;@1c9a281
ContentLength: 9
java.lang.Integer
java.lang.String
java.lang.String
java.lang.Integer
RaceData Table Size 20
RaceData #5 Content: [Ljava.lang.Object;@160f330
ContentLength: 9
java.lang.Integer
java.lang.String
java.lang.String
java.lang.Integer
RaceData Table Size 20
RaceData #6 Content: [Ljava.lang.Object;@afaaa9
ContentLength: 9
java.lang.Integer
java.lang.String
java.lang.String
java.lang.Integer
RaceData Table Size 20
RaceData #7 Content: [Ljava.lang.Object;@10787c3
ContentLength: 9
java.lang.Integer
java.lang.String
java.lang.String
java.lang.Integer
RaceData Table Size 20
RaceData #8 Content: [Ljava.lang.Object;@16ae608
ContentLength: 9
java.lang.Integer
java.lang.String
java.lang.String
java.lang.Integer
RaceData Table Size 20
RaceData #9 Content: [Ljava.lang.Object;@1f76ca6
ContentLength: 9
java.lang.Integer
java.lang.String
java.lang.String
java.lang.Integer
RaceData Table Size 20
RaceData #10 Content: [Ljava.lang.Object;@327893
ContentLength: 9
java.lang.Integer
java.lang.String
java.lang.String
java.lang.Integer
RaceData Table Size 20
RaceData #11 Content: [Ljava.lang.Object;@180d549
ContentLength: 9
java.lang.Integer
java.lang.String
java.lang.String
java.lang.Integer
RaceData Table Size 20
RaceData #12 Content: [Ljava.lang.Object;@18a3317
ContentLength: 9
java.lang.Integer
java.lang.String
java.lang.String
java.lang.Integer
RaceData Table Size 20
RaceData #13 Content: [Ljava.lang.Object;@1c0ed1c
ContentLength: 9
java.lang.Integer
java.lang.String
java.lang.String
java.lang.Integer
RaceData Table Size 20
RaceData #14 Content: [Ljava.lang.Object;@f9f097
ContentLength: 9
java.lang.Integer
java.lang.String
java.lang.String
java.lang.Integer
RaceData Table Size 20
RaceData #15 Content: [Ljava.lang.Object;@102555c
ContentLength: 9
java.lang.Integer
java.lang.String
java.lang.String
java.lang.Integer
RaceData Table Size 20
RaceData #16 Content: [Ljava.lang.Object;@1c6c4e0
ContentLength: 9
java.lang.Integer
java.lang.String
java.lang.String
java.lang.Integer
RaceData Table Size 20
RaceData #17 Content: [Ljava.lang.Object;@1367309
ContentLength: 9
java.lang.Integer
java.lang.String
java.lang.String
java.lang.Integer
RaceData Table Size 20
RaceData #18 Content: [Ljava.lang.Object;@145f30
ContentLength: 9
java.lang.Integer
java.lang.String
java.lang.String
java.lang.Integer
RaceData Table Size 20
RaceData #19 Content: [Ljava.lang.Object;@1ef50db
ContentLength: 9
java.lang.Integer
java.lang.String
java.lang.String
java.lang.Integer

I´m wondering what i am doing wrong that causes not to return the AnchorPanes for the rows i want to update.

Is there some tutorial about it? Does someone have an idea what could be wrong?

As i am in a very early stage of the app i can switch to another Object if it make sense to use another TableObject (if available).

Or should i simple switch to xCLV (xCustomListView)? Time writing it i think i should give it a short try. I expect it to be easy to switch as i am more familar with xCLV instead of TableView ;-)

Any hints/tips are highly welcome
 
Last edited:

udg

Expert
Licensed User
Longtime User
Hi Don,

why in your tableview initialization you use
B4X:
rd.GetTable.Items.Set(o,Array As Object...."
instead of rd.GetTable.Items.AddAll ?
I expected an error on Set because the Items list should be empty at the time and you're tryng to replace an non-existing item. Am I wrong?

Another point to check. calling the testing code after initialization you have ContentLength: 10, but when you're ready to update a value you get ContentLength: 9

Class DBUtils is, generally speaking, very useful to manage table data.
 
Upvote 0

Magma

Expert
Licensed User
Longtime User
Hi there...

Hope that helps:

If use it change the name of tableview and... i did a fast copy / paste from my code (didn't have time to full check your code)

B4X:
Dim values(TableView0.ColumnsCount) As String = TableView0.Items.Get(k)  'where k is the row of table

'So to get the old values of columns just use:
'values(x) ' where x the column number

'To set new values at specific columns use that:
'set new values at values(x)... ex:
'values(1)="123231"
TableView0.Items.Set(k,values) 'k is the row and values is the array tith new column values...
 
Upvote 0

Daestrum

Well-Known Member
Licensed User
Longtime User
Another point to check. calling the testing code after initialization you have ContentLength: 10, but when you're ready to update a value you get ContentLength: 9

One of the fields (verbesserung (position change??)) is calculated from grid position and actual position, hence only 9 data fields read.

The code for calculating the position change looks odd
B4X:
        If o=gridpos Then
            verbesserung = 0
        else if o > gridpos Then
            verbesserung = gridpos-o
        else if o < gridpos Then
            verbesserung = gridpos-o
        End If
Unless o = gridpos the if statement executes the same logic.(maybe you just need an else in place of the two 'if else' 's.
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
About the TableView. Never mind. I just replaced it with xCLV and it is working fine.
verbesserung (position change??)
Yes, it should reflect the change in the race.

tv_032.png

Hamilton ends the race at place 20. He lost 16 places from the Racebegin. Sirotin started from the end of the Grid.

I know its unfair... I am driving hamilton but due to the fact i am testing the tool i do not really drive... i get disqualified all the time ;-)

Thank you all for your answers.

For this tool i´ll use the xCLV as i am more familar with and i already replaced the Tableview with the CLV.
 
Upvote 0
Top