B4A Library [Class] Flexible Table

klaus

Expert
Licensed User
Longtime User
Sorry, but you do not give enough information.
In what condition do you get the problem ?
How do you define the Table ?
Are you changing the colors ?

The best way to help you efficiently would be if you posted a small project showing the problem.
 

mzsoft

Member
Sorry, but you do not give enough information.
In what condition do you get the problem ?
How do you define the Table ?
Are you changing the colors ?

The best way to help you efficiently would be if you posted a small project showing the problem.
no.not change color.


B4X:
    Table1.Initialize(Me, "Table1")
    Table1.AddToActivity(pan_table_sample, 0,0, 100%x, 100%y)
    Table1.InitializeTable(7,Gravity.CENTER,False)
    Table1.SetHeader(Array As String("..", "..", "..", ".." , "..","..",".."))
    Table1.SetColumnsWidths (Array As Int(10%x,10%x,35%x,20%x,25%x,20%x,20%x))

and in loop i add data.

B4X:
Dim row(7) As Object=Array As String(k2,cd1.user_id,cd1.name,cd1.mahsool,cd1.date,cd1.time,minutes_to_string(time))   
Table1.AddRow(row)

thats it.
 

esyak

New Member
Licensed User
How does the problem appear?
I cannot reproduce it in the demo program.
It's the same problem i faced here: https://www.b4x.com/android/forum/threads/class-flexible-table.30649/post-769955

Happen when there are lots of rows loaded (+100), the cell allignment is center and it's completly random. The cell background becomes the same of the table background. If you click on the row, or swipe someway down (or up) and then return back, the row go back to normal color.
 
Last edited:

klaus

Expert
Licensed User
Longtime User
It seems that it depends on the device.
The attached program works OK on my Samsung Galaxy S10 but I see some rows with the wrong color on my Samsung Tablet S6 Lite.
The behavior is different depending on the scroll speed.
I do not know yet why this happens, need to look deeper into it.
 

Attachments

  • TestTableRowColors.zip
    34.7 KB · Views: 236

Sergey_New

Well-Known Member
Licensed User
Longtime User
Tell me, please, is it possible to programmatically remove the selection of a row with a known number?
 

vecino

Well-Known Member
Licensed User
Longtime User
RowColor1 if it is an odd number.
RowColor2 if it is an even number.
 

Sergey_New

Well-Known Member
Licensed User
Longtime User
This is clear:
B4X:
Public Sub UnSelectRow(Row As Int)
    Dim rowColor As Int
    If Row Mod 2 = 0 Then
        rowColor = Row1Color
    Else
        rowColor = Row1Color
    End If
    ...
End Sub
How to set rowColor to the desired row?
 

klaus

Expert
Licensed User
Longtime User
Which version are you using ?

This is the routine in the Table class:

B4X:
'Unselects the row for the given index
Public Sub UnselectRow(Row As Int)
    If Not(cAllowSelection) Then Return
    
    Dim prevIndex As Int
    
    prevIndex = SelectedRows.indexof(Row)     ' -1 if selecting not a selected row
    If prevIndex > -1 Then
        ' if mMultiSelect = True no column change, only if mMultiSelect = False
        SelectedCol = -1
        SelectedRows.RemoveAt(prevIndex)
        If visibleRows.ContainsKey(Row) Then
            HideRow(Row)
            ShowRow(Row)
        End If
    End If
End Sub
 

Sergey_New

Well-Known Member
Licensed User
Longtime User
Which version are you using ?

This is the routine in the Table class:
I am using version 1.44
Procedure UnselectRow I see in version 3.30
 

klaus

Expert
Licensed User
Longtime User
I made some trials to solve the problem related in posts #180 to #185 about the wrong row colors.
It is due to the lazy loading and depends on the scroll speed and the device.
Unfortunately I have not found a solution yet, I need to investigate further.
 

Oscarin

Member
Is it possible to start with an empty grid (just the headers) so the user enters data and then add it to the grid?
 

klaus

Expert
Licensed User
Longtime User
Sure.
Add the Table in the Designer.
Set the NumberOfColumns.
In the code set the Headers with for example:
B4X:
MyTable.SetHeader(Array As String ("First name", "Last name", "City"))
If you have an EditText view for each column item simply add a new line in the Table with:
B4X:
MyTable.AddRow(Array As String(edtFirstName.Text, edtLastName.Text, edtCity.Text))
 

Oscarin

Member
Thanks for the reply,
I have added the class to my project
I added the table in the designer
I set the NumberOfColumns
I set the headers like in your example
I set Tanble1 as Table
Table1.SetHeader(Array As String ("Description", "Qty 1", "Qty 2"))

but I get the following error on the table class

B4A Version: 11.20
Parsing code. Error
Error parsing program.
Error description: Unknown type: cursor
Are you missing a library reference?
Error occurred on line: 3395 (Table)
Private Sub CheckColumnDataTypes(MyCurs As Cursor) As String()


Thanks for any help
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…