B4A Library [Class] Flexible Table

Kanne

Member
Licensed User
Longtime User
so do I ?
It's running fantastic now. After optimizing the trigger for table-refresh my GUI feels very smooth.
I noticed that sometimes the "ShowStatusLine = False" is reset by other statements ("SetAutomaticWidths","NumberOfFixedColumns", ... ? could not test in detail),
so after filling, hiding cols, autowidth, etc. I allways do a "ShowStatusLine = False" and it's doing what I want.
 

Kanne

Member
Licensed User
Longtime User
Hi Klaus,
I just made some tests:

1. can't also reproduce the problem with ShowStatusLine - maybe it's gone

2. NumberOfFixedColumns and SetAutomaticWidths unhides columns
don't know if this is wanted but I wondered why my hidden cols were shown after SetAutomaticWidths;
on the other hand we have an undocumented method "show all hidden cols" by SetAutomaticWidths
- you only have to be aware to use "hideCol" at the end

3. problem with new function "InnerTotalWidth":
if table has fixed cols and is smaller than panelwidth I get wrong values by InnerTotalWidth for centering the table;
so I used my old function (sum of width of cols) and compared them:
example1: 100%x:1280 InnerTotalWidth:1896 JK_Codes.TableGetColumnWidthsTotal:702
example2: 100%x:1280 InnerTotalWidth:1890 JK_Codes.TableGetColumnWidthsTotal:696
Well, I think that when using "sum of cols" the gridlines etc. will be missing, you may take a look on it
 

Attachments

  • ex1.jpg
    175.4 KB · Views: 240
  • ex2.jpg
    239.2 KB · Views: 225

klaus

Expert
Licensed User
Longtime User
2. Don't you set the properties in the Designer?
If it's a problem I will look further.

3. What is the value of LineWidth? I suppse 3 pixels.
I suppose that the difference comes from the first and last vertical lines.
The InnerTotalWidth property returns the sum of the two headers.
 

Kanne

Member
Licensed User
Longtime User
2. I don't use the designer and add the table by code. the hidden cols are depending on the sql-statements and so differs.
I would leave it as it is (due to the fact I can unhide all cols with SetAutomaticWidths) - maybe a hint in documentation that calling SetAutomaticWidths unhides the cols would be nice

3. yes I'm using "Table1.LineWidth = 3dip" but the vertical lines can't be the reason for the difference of 1896 to 702 when showing 7 cols ...
 

RB Smissaert

Well-Known Member
Licensed User
Longtime User
Had a look at the latest version as I was interested in the new sort icons. All working very nicely.
I noticed that it still uses the slow selection sort and wonder if it could be changed to the much
faster method with sorting types in a list eg:

DataSorted.SortType("lLong", bAscending)
where DataSorted is the list holding the types.

I am using this method for the 2 years now in the edited Flexible table class and all working very well.
I am happy to post my latest code (changed quite a bit from 2 previous postings as it incorporates now setting
table text colour and table row colour) if that is helpful.

RBS
 

makis_best

Well-Known Member
Licensed User
Longtime User
I try to use version 3_15 and I get below error.
I insert records using a loop added by user.
B4X:
Aspect ratio: 0.5875
Error occurred on line: 1030 (Table)
java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
    at java.util.ArrayList.get(ArrayList.java:411)
    at anywheresoftware.b4a.objects.collections.List.Get(List.java:117)
    at gr.iosif.droidview.table._showrow(table.java:1574)
    at gr.iosif.droidview.table._addrowautomaticwidth(table.java:902)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:732)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:351)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:144)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:180)
    at anywheresoftware.b4a.debug.Debug.delegate(Debug.java:262)
    at gr.iosif.droidview.main._stoxos(main.java:1554)
    at gr.iosif.droidview.main$ResumableSub_Activity_Create.resume(main.java:1447)
    at anywheresoftware.b4a.shell.DebugResumableSub$DelegatableResumableSub.resumeAsUserSub(DebugResumableSub.java:48)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:732)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:351)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:144)
    at anywheresoftware.b4a.BA.raiseEvent(BA.java:176)
    at anywheresoftware.b4a.shell.DebugResumableSub$DelegatableResumableSub.resume(DebugResumableSub.java:43)
    at anywheresoftware.b4a.BA.checkAndRunWaitForEvent(BA.java:250)
    at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:137)
    at anywheresoftware.b4a.BA$2.run(BA.java:370)
    at android.os.Handler.handleCallback(Handler.java:751)
    at android.os.Handler.dispatchMessage(Handler.java:95)
    at android.os.Looper.loop(Looper.java:154)
    at android.app.ActivityThread.main(ActivityThread.java:6186)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:889)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:779)
 

klaus

Expert
Licensed User
Longtime User
I noticed that it still uses the slow selection sort and wonder if it could be changed to the much
faster method with sorting types in a list ...
Yes, I know. If I remember well I looked at your code and it used other modules and I found it complicated to include it in the class.
I was afraid do introduce more bugs than adding a new feature.
 

klaus

Expert
Licensed User
Longtime User
I try to use version 3_15 and I get below error.
You need to give more information on how you add rows.
The best way to help you would be if you posted your project or a smaller one showing the problem.
 

makis_best

Well-Known Member
Licensed User
Longtime User
You need to give more information on how you add rows.
The best way to help you would be if you posted your project or a smaller one showing the problem.

My code with version 3.10 working just fine.
One example of code.
B4X:
StoxosTable.InitializeTable(8, Gravity.CENTER, False)
    StoxosTable.SetHeader(Array As String("Μήνας", "Τζίρος πρ. χρήσης", "Προϋπ/μος πρ. χρήσης", "% απόκλισης πρ. χρήσης", "Τζίρος τρ. χρήσης", _
    "Προϋπ/μος τρ. χρήσης", "% απόκλισης τρ. χρήσης", "% σύγκρισης τζίρων χρήσεων"))
    StoxosTable.SetColumnsWidths(Array As Int(120dip, 120dip, 120dip, 120dip, 120dip, 120dip, 120dip, 120dip))
    StoxosTable.StatusLine = False
    SQlScript = $"SELECT MonthName, BudgetTurnover_current, BudgetTurnover_previous,
                   TradeAccount_GID, Turnover1, Turnover2, perc1, perc2, perc3 
                   FROM LOCAL_Salesman_Budget ORDER BY MonthNumber1, MonthNumber2"$
    Curs1 = Starter.LocalSQL.ExecQuery(SQlScript)

     For ii = 0 To Curs1.RowCount - 1
        Curs1.Position = ii
        StoxosTable.AddRowAutomaticWidth(Array As String(Curs1.GetString("MonthName"), _   ------> Crash here
        NumberFormat2(Curs1.GetDouble("Turnover2"), 1, 0, 2, False) & " €", _
        NumberFormat2(Curs1.GetDouble("BudgetTurnover_previous"), 1, 0, 2, False) & " €", _
        NumberFormat2(Curs1.GetDouble("perc2"), 1, 0, 2, False) & "%", _
        NumberFormat2(Curs1.GetDouble("Turnover1"), 1, 0, 2, False) & " €", _
        NumberFormat2(Curs1.GetDouble("BudgetTurnover_current"), 1, 0, 2, False) & " €", _
        NumberFormat2(Curs1.GetDouble("perc1"), 1, 0, 2, False) & "%", _
        NumberFormat2(Curs1.GetDouble("perc3"), 1, 0, 2, False) & "%"))
        Pt1 = Pt1 + NumberFormat2(Curs1.GetDouble("Turnover2"), 1, 0, 2, False)
        Pt2 = Pt2 + NumberFormat2(Curs1.GetDouble("BudgetTurnover_previous"), 1, 0, 2, False)
        Pt3 = Pt3 + NumberFormat2(Curs1.GetDouble("Turnover1"), 1, 0, 2, False)
        Pt4 = Pt4 + NumberFormat2(Curs1.GetDouble("BudgetTurnover_current"), 1, 0, 2, False)
    Next
    StoxosTable.AddRowAutomaticWidth(Array As String("Σύνολα", NumberFormat2(Pt1, 1, 0, 2, False) & " €", NumberFormat2(Pt2, 1, 0, 2, False) & " €", "", NumberFormat2(Pt3, 1, 0, 2, False) & " €", NumberFormat2(Pt4, 1, 0, 2, False) & " €", "", ""))
 
Last edited:

RB Smissaert

Well-Known Member
Licensed User
Longtime User
Yes, I know. If I remember well I looked at your code and it used other modules and I found it complicated to include it in the class.
I was afraid do introduce more bugs than adding a new feature.

Yes, I agree it adds some complexity, even more so now that I have added the option to colour specified rows (text or label colour), as the
colours need to be sorted along the data. When I have this fully worked out I am happy to add the list of types sort to your code as it is
(which is different than my altered Flexible table class) and pass it to you for testing.
In any case, thanks for this Flexible table class.

RBS
 

makis_best

Well-Known Member
Licensed User
Longtime User
Please test the attached Table.bas module version 3.16.
There was a bug in AddRowAutomaticWidth, introduced in version 3.15.

Keep crashing....

B4X:
Private Sub ShowRow(Row As Int)
    Private i As Int

    If visibleRows.ContainsKey(Row) Then Return
    'Log("ShowRow: " & row)
    Dim lbls() As Label
    Dim values() As String
    lbls = GetLabels(Row)
    values = Data.get(Row)
    visibleRows.Put(Row, lbls)
    Dim rowColor() As Object
    Private txtColor As Int
    If (SelectedRows.indexof(Row) <> -1 )Then
        rowColor = SelectedDrawable
        txtColor = cSelectedRowTextColor
    Else If lstRowColorIndexes.Get(Row) > 1 Then      ---------------->    HERE!!!!
        rowColor = lstRowDrawables.Get(lstRowColorIndexes.Get(Row) - 2)
'        txtColor = cTextColor
        txtColor = GetContrastColor(lstRowColors.Get(lstRowColorIndexes.Get(Row) - 2))
    Else
        If Row Mod 2 = 0 Then
            rowColor = Drawable1
            txtColor = cTextColor
        Else
            rowColor = Drawable2
            txtColor = cTextColor
        End If
    End If

Error:
 

Kanne

Member
Licensed User
Longtime User
Hi Klaus,
I just tested your project - nearly crashing when pushing any button - I'm a bit worried of using it.
Cheking the problem with "getInnerTotalWidth" : seems to be ok now !
 
Last edited:
Cookies are required to use this site. You must accept them to continue using the site. Learn more…