B4A Library [Class] Flexible Table

fishwolf

Well-Known Member
Licensed User
Longtime User
i'm trying to use SetRowColorN, but i have a error to runtime

B4X:
table_setrowcolorn (java line: 5904)
java.lang.IndexOutOfBoundsException: Invalid index 0, size is 0
    at java.util.ArrayList.throwIndexOutOfBoundsException(ArrayList.java:255)
    at java.util.ArrayList.set(ArrayList.java:481)
    at anywheresoftware.b4a.objects.collections.List.Set(List.java:123)
    at b4a.TableDemo308.table._setrowcolorn(table.java:5904)
    at b4a.TableDemo308.main._activity_create(main.java:376)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:213)
    at b4a.TableDemo308.main.afterFirstLayout(main.java:105)
    at b4a.TableDemo308.main.access$000(main.java:17)
    at b4a.TableDemo308.main$WaitForLayout.run(main.java:83)
    at android.os.Handler.handleCallback(Handler.java:743)
    at android.os.Handler.dispatchMessage(Handler.java:95)
    at android.os.Looper.loop(Looper.java:150)
    at android.app.ActivityThread.main(ActivityThread.java:5621)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:794)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:684)

B4X:
Sub Activity_Create(FirstTime As Boolean)
   
    Table1.Initialize(Me, "TableResults")
    Table1.AddToActivity(Activity, 0, 0, 100%x, 100%y)
    Table1.InitializeTable(10, Gravity.CENTER_HORIZONTAL, True)
   
    Table1.SetHeader(Array As String("Data", "Prove", "Arr", "Tp", "E/R", "Pen", "Qual", "Extra1", "Extra2", "Extra3"))

    Table1.SetColumnsWidths(Array As Int(25%x, 25%x, 25%x, 25%x, 25%x, 25%x, 25%x, 25%x, 25%x, 25%x))

    Dim Alignments() As Int
    Alignments = Array As Int(Gravity.LEFT, Bit.Or(Gravity.LEFT, Gravity.CENTER_VERTICAL), Gravity.CENTER, Gravity.LEFT, Gravity.LEFT, Gravity.LEFT, Gravity.LEFT, Gravity.LEFT, Gravity.LEFT, Gravity.LEFT)
    Table1.SetHeaderAlignments(Alignments)
    Table1.SetCellAlignments(Alignments)
   
   
    For Ind = 0 To 20
        Table1.SetRowColorN(Ind, Colors.Green)
        Table1.AddRow(Array As String(Ind, "bbbbbb", "cccccc", "dddddd", "eeeeee", "ffffff", "gggggg", "hhhhhh", "iiiiii", "yyyyyy") )
    Next  
   
    Table1.FirstColumnFixed = True
   
End Sub
 

fishwolf

Well-Known Member
Licensed User
Longtime User
[QUOTE = "klaus, post: 758114, membro: 904"]
Prova questo :
[CODE = b4x] Per Ind = da 0 a 20
Table1.AddRow (Array As String (Ind, "bbbbbb", "cccccc", "dddddd", "eeeeee", "ffffff", "gggggg", "hhhhhh", "iiiiii", "yyyyyy"))
Table1.SetRowColorN (Ind, Colors.Green)
Avanti [/ CODE]
[/CITAZIONE]
no error is showed, ma only the rows from 13 to 20 are green
from 1 to 12 are with 2 default colors
 

fishwolf

Well-Known Member
Licensed User
Longtime User
if reload the data table and change color (click on cell) some color rows are wrong

attach the demo project
 

Attachments

  • Table.zip
    32.3 KB · Views: 261
Last edited:

Kanne

Member
Licensed User
Longtime User
well, it seems that there is a problem when looking up for the color when the color is a large negative value.
SetRowColorN then allways add's the color to the colorlist - even when already within the list:
B4X:
Public Sub SetRowColorN(Row As Int, Color As Int)
    Private col As Int
    Private New = False As Boolean
    If lstRowColors.IndexOf(Color) > 0 Then
        lstRowColorIndexes.Set(Row, lstRowColors.IndexOf(Color) + 2)
    Else
        lstRowColors.Add(Color)
        lstRowColorIndexes.Set(Row, lstRowColors.Size + 1)    'specific row color indexes begin with 2
        New = True
    End If

Klaus may take a look on that - I use the callback function for colorization and this will also work on your project:
B4X:
Sub ShowTable
    Table1.ClearAll
    For Ind = 0 To 19
        Table1.AddRow(Array As String(Ind, "bbbbbb", "cccccc", "dddddd", "eeeeee", "ffffff", "gggggg", "hhhhhh", "iiiiii", "yyyyyy") )
    Next
End Sub

Sub Table1_CellClick(col As Int, row As Int)
    If Color = Colors.Red Then
        Color = Colors.Yellow
    Else
        Color = Colors.Red
    End If
    ShowTable
End Sub

Sub Table1_ShowRow(row As Int, lbls() As Label)
    For i = 0 To lbls.length - 1
        If row=5 Or row=10 Or row=15 Then
            lbls(i).Color = Color
        Else
            lbls(i).Color = Colors.Green
        End If
    Next
End Sub
 

fishwolf

Well-Known Member
Licensed User
Longtime User

in prod application color depends from data values
how to access to columns value from callback?
 

Kanne

Member
Licensed User
Longtime User
you can examine the text of every label like this
B4X:
Sub Table1_ShowRow(row As Int, lbls() As Label)
    For i = 0 To lbls.length - 1
        If row=5 Or row=10 Or row=15 Then
            lbls(i).Color = Color
        Else
            Select True
                Case lbls(i).Text.StartsWith("b")
                    lbls(i).Color = Colors.Blue
                Case lbls(i).Text.StartsWith("c")
                    lbls(i).Color = Colors.Magenta
                Case lbls(i).Text.StartsWith("d")
                    lbls(i).Color = Colors.Cyan
                Case Else
                    lbls(i).Color = Colors.Green
            End Select
        End If
    Next
End Sub
 

klaus

Expert
Licensed User
Longtime User
The Table Class has been updated to version 3.26
Amended problem with sort with remove accents
Amended problem with SetRowColorN
Added SetCellAlignmentColN method
Added SetHeaderAlignmentColN method
how to access to columns value from callback?
You can get the value with:
B4X:
Value = Table1.GetValue(Col, Row)
 

esyak

New Member
Licensed User
Hi, I have a problem with the background color of some cells after loading the table (via sqlite if matters). The problem is that if i scroll the table (with about 100 elements) at some point the background color of some cells in columns changes. The color (rowcolor1 & rowcolor2) is set in the designer only. After some tries, i found that the background of rowcolor (1 & 2) become the same of the table. If i click on cell, the color return to the normal one.

 
Last edited:

esyak

New Member
Licensed User
Currently I am not at home, will be back on Sunday.
Can you post a small project showing the problem.
It's a simple Table1.LoadSQLiteDB(Connessione.mySQL,Strsql,True)
where Strsql is a string with a query, nothing more.
 

Sergey_New

Well-Known Member
Licensed User
Longtime User
Using together B4XDialog and Table.
When the dialog is closed, a white or black background appears in place of the keyboard, depending on the installed theme. How can avoid this?
An example is attached.
 

Attachments

  • TableExample.zip
    28.1 KB · Views: 216

klaus

Expert
Licensed User
Longtime User
Sorry, but I don't understand the problem.
You need to fill the table with data to see something.
The Table class doesn't check the theme and does not change any color according to the selected theme.
All the colors can be defined in the Designer or changed in the code.
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…