B4A Library [Class] Flexible Table

stu14t

Active Member
Licensed User
Longtime User
This is of course much easier, but you didn't tell us that you have the table content in process global array.

i just dawned on me after i'd made the post, looked through all the code in the two classes and scratched my head a few times.

Apologies if I've wasted time here
 

tdocs2

Well-Known Member
Licensed User
Longtime User
Greetings, all.

Once more, my gratitude to Klaus for giving his time to provide us with this wonderful Flexible Table Class.

This is more of a wish than a question, but I will go ahead and ask for it.

It would be GREAT to add, to this Flexible Table Class, a PRINT TABLE feature for Cloud ready printers based on the new post v4.4 Print Framework in Android. If it can be done to retrofit back to 4.0, that would even be better, but I dare not ask.

I have read about the Print Framework but the Java Object and Java itself are well beyond my technical skills.

Best regards and thank you for your consideration.

Sandy
 

Turbo3

Active Member
Licensed User
Longtime User
After using LoadTableFromCSV2 how can I get it to display the last row (i.e. the bottom of the table) instead of defaulting to the top of the table?

I thought I could just follow the LoadTable... immediately with a JumpToRow() but that does not work. You end up with a partial or full red screen (or whatever your dividing line color is set to).

Looks like I need away to know when the screen is ready to accept the JumpToRow command.
 
Last edited:

vecino

Well-Known Member
Licensed User
Longtime User
Hello friends, I have been doing tests to try to find out why it is slower.
And I found this:
SelectedRowColor: 487
SelectedCellColor: 370
RowColor: 774
Mainly in "RowColor"

I have done the following:
B4X:
Sub iniciar
    fTicksIni=DateTime.Now
End Sub

Sub terminar( cProcess As String )
    fTicksFin=DateTime.Now
    Log(cProcess &": "& (fTicksFin-fTicksIni) )
End Sub

B4X:
Sub LeerTabla
    Dim cSql As String
    Dim c0,c1,c2,c3 As String        ' variables para recoger datos del registro
    Dim iW1,iW2,iW3,iW4 As Int    ' anchos de columnas
    Dim iX As Int
    Dim iAlineado() As Int            ' alineado de cada columna
    '
    If Not (bFiltrado) Then
        cSql = "select codigo, nombre, desdemesa, hastamesa from "&cTabla&" order by codigo"
    Else
        cSql = cSqlFiltro
    End If
    '
    cCodigoActual = ""
    '
    If Q.IsInitialized Then
        Q.Close
    End If
    '
iniciar
    Q = globales.DBconex.ExecQuery(cSql)
terminar("ExecQuery")
    '
'    ProgressDialogShow("")
    '
    If Q.RowCount>0 Then
        If Not (tbTabla.IsInitialized) Then
            iniciar
            tbTabla.Initialize(Me,"tbTabla",4,Gravity.CENTER,False)    ' 4 columnas
            terminar("Initialize")    
            iniciar
            tbTabla.AddToActivity(pnLista,0,0,pnLista.Width,pnLista.Height)        
            terminar("AddToActivity")                
            iniciar
            tbTabla.SetHeader(Array As String(globales.lMsg.get(5),globales.lMsg.get(6),globales.lMsg.get(52),globales.lMsg.get(53)))    'tbTabla.SetHeader(Array As String("Código","Nombre"))
            terminar("SetHeader")                
        End If
    
        iniciar
        tbTabla.TextSize = 16    
        terminar("TextSize")
        iniciar
        tbTabla.HeaderTextColor = Colors.Yellow    
        terminar("HeaderTextColor")

        iniciar
        tbTabla.SelectedRowColor  = globales.iColorSeleccionado
        terminar("SelectedRowColor")            
        iniciar
        tbTabla.SelectedCellColor = globales.iColorSeleccionado
        terminar("SelectedCellColor")            
        '
        iniciar
        tbTabla.RowColor1 = globales.iColorNon
        tbTabla.RowColor2 = globales.iColorPar
        terminar("RowColor")                    
        '
        tbTabla.ClearAll
        '
        For iX=0 To Q.RowCount-1
            Q.Position=iX
            ' asignar valores
            c0 = (Q.GetString2(0)).trim    ' codigo
            c1 = (Q.GetString2(1)).trim    ' descripcion
            c2 = (Q.GetString2(2)).trim    ' desdemesa
            c3 = (Q.GetString2(3)).trim    ' hastamesa
            ' añadir a la fila
            iniciar
            tbTabla.AddRow(Array As String(c0,c1,c2,c3))        
            terminar("AddRow")                        
            '        
        Next
        '
        ' ancho de las columnas    
        iW1 = (20*pnFondo.Width)/100
        iW2 = (40*pnFondo.Width)/100
        iW3 = (20*pnFondo.Width)/100
        iW4 = (20*pnFondo.Width)/100
        '
        iniciar
        tbTabla.SetColumnsWidths(Array As Int(iW1,iW2,iW3,iW4))
        terminar("SetColumnsWidths")                    
        '    
        iniciar
        iAlineado = Array As Int( Gravity.center,Gravity.left,Gravity.center,Gravity.center )
        tbTabla.SetCellAlignments( iAlineado )
        terminar("SetCellAlignments")                    
        '    
        cEstado = ""
        '
    End If
    '
    If Q.RowCount=0 Then
        Msgbox(globales.lMsg.get(24),globales.lMsg.get(9))    ' Msgbox("¡No hay datos!","Aviso")
    End If
    '
    If Q.IsInitialized Then    Q.Close
    '
    ShowDefault
End Sub

And the result:

 

vecino

Well-Known Member
Licensed User
Longtime User
There is no difference:
ExecQuery: 0
Initialize: 516
SelectedRowColor: 363
SelectedCellColor: 467
RowColor: 763
AddToActivity: 361
SetHeader: 4
TextSize: 0
HeaderTextColor: 0
AddRow: 2
AddRow: 2
AddRow: 3
SetColumnsWidths: 0
SetCellAlignments: 7
 

ivan.tellez

Active Member
Licensed User
Longtime User
Hello friends, I have been doing tests to try to find out why it is slower.
And I found this:
Mainly in "RowColor"

Are you using the last version --> 1.36 ???

This was a problem I reported and is now solved in this version.

Just configure the table before adding to the view
 

klaus

Expert
Licensed User
Longtime User
SelectedRowColor: 363
SelectedCellColor: 467
RowColor: 763

RowColor is about the double of SelectedRowColor or SelectedCellColor.
But for RowColor you change two properties and only one for SelectedRowColor and SelectedCellColor.
Try to comment the two setRowColor routines in the class and set the two cRowColor variables to public and change the values directly in the main code to see if it's the call to the setProperty routines which takes time.
Or post your test project as a zip file and I will check it.

Do you have the code with the IsInitialized check in the RowColor routine like below ?
B4X:
Public Sub setRowColor1(Color As Int)
    cRowColor1 = Color
    If pnlTable.IsInitialized Then
        innerClearAll(NumberOfColumns)
    End If
End Sub
 

vecino

Well-Known Member
Licensed User
Longtime User
Hello, I tested Table:
B4X:
'sets or gets the odd rows color
Public Sub setRowColor1(Color As Int)  
   cRowColor1 = Color
funciones.iniciar  
   innerClearAll(NumberOfColumns)
funciones.terminar("innerClearAll")  
End Sub

'sets OR gets the even rows color
Public Sub setRowColor2(Color As Int)
   cRowColor2 = Color
funciones.iniciar  
   innerClearAll(NumberOfColumns)
funciones.terminar("innerClearAll")  
End Sub

And the result is:
innerClearAll: 403
innerClearAll: 361
innerClearAll: 395
innerClearAll: 394
 

vecino

Well-Known Member
Licensed User
Longtime User
Hello, the problem is here:
B4X:
For i = 1 To 80 'fill the cache to avoid delay on the first touch
  LabelsCache.Add(CreateNewLabels)
Next

In the sub: Private Sub innerClearAll(vNumberOfColumns As Int)
 

vecino

Well-Known Member
Licensed User
Longtime User
B4X:
For i = 1 To 80 'fill the cache to avoid delay on the first touch
  LabelsCache.Add(CreateNewLabels)
Next
Hi, I do not understand the code. What is it exactly?
 

LucaMs

Expert
Licensed User
Longtime User
I would like to make a suggestion.

It would involve a small revolution but would result in great benefits.

Add a class to represent a cell (including its value), for example TableCell.

In this way it will be possible to format each cell, with TextSize, TextColor etc but also set backgrounds of various types and set bitmaps as value!

Probably it would be helpful to create three classes:

TableView (the simple name Table can be confusing and do think of a database table), TableRow and TableCell.


----

Without doing this "revolution", I have made some twisted change to set/get the background of the cells.

This has resulted in changes to cell values, which are stored in the Data List.
The textual values are preceded by a "symbol" and by an index, which refers to a background stored in an array.

So, there are some functions for encoding/decoding of the text which is then displayed in the cell.

It is rather convoluted but functional; I repeat, having classes TableCell (and TableRow) everything would be easier and cleaner.


I have to make some more changes, but if you want I will publish THIS my version (not the ideal one with TableCell, I have not developed it)



[P.S. the purpose is to get something like this (with the addition of headers for rows and columns):
 
Last edited:
Cookies are required to use this site. You must accept them to continue using the site. Learn more…