B4A Library [Class] TableView - Supports tables of any size

An improved version of this class is available here: http://www.basic4ppc.com/forum/addi...icial-updates/30649-class-flexible-table.html

The Table class allows you to show tables of any sizes. The views (labels) are reused to avoid creating many views.

With the help of StringUtils the table can be loaded and saved to a CSV file. It shouldn't be difficult to show SQL tables using DBUtils.ExecuteMemoryTable.


Follow the attached example to see how the class is used. To add it to your own project you need to add the class module to your project and add a reference to StringUtils library.

RemoveRow code is available here: http://www.basic4ppc.com/forum/showpost.php?p=146795&postcount=147

V1.10 uploaded. New method: SetColumnsWidths. Allows you to manually set the width of each column
V1.11 uploaded. Fixes a bug with grey stripes appearing.


  • Table.zip
    14.9 KB · Views: 6,617
Last edited:


Well-Known Member
Licensed User
Screenshot looks great! Haven't upgraded to v2 yet, still, just out of curiosity, did you use a webView for this?


Well-Known Member
Licensed User
No. It is a ScrollView with labels. As written above the labels are reused to avoid adding many labels (like the previous implementation).
I see. True, it's much more efficient to use just a tiny area of labels, I totally agree. Another one: Is this table scrollable horizontally? I remember an old discussion about this, when we were talking about choosing a webView when we want something like this.

Finally, as I've already said, I haven't yet upgraded. It's just a matter of a little 'fear' about compile error, while I'm in the middle of an important app for me. I hope my fears are not logical.


Licensed User
Is this table scrollable horizontally? I remember an old discussion about this, when we were talking about choosing a webView when we want something like this.
If you look at the Treeview class in this forum, you'll see it's fairly easy to add horizontal scrolling to a ScrollView.


Licensed User
As it is based on ScrollView it doesn't support horizontal scrolling.

I'm sure than it needs that row.height is to be optionally auto-adjusted for longest cell content (maybe up to, say, 90% of ScrollView.Height, if scrolling problem), like i used:

Sub AdjustHeight (Obj As Label)
Dim A As StringUtils, t As Int
t = A.MeasureMultilineTextHeight(Obj, Obj.Text)
Obj.Height = t
End Sub

'Adds a row to the table
Sub AddRow(Values() As String)
   If Values.Length <> NumberOfColumns Then
      Log("Wrong number of values.")
   End If
   Dim lastRow As Int, BiggestHeight As Int, Lprev, a As Label, RowHeight2, RowHeight2_1 As Int
   lastRow = NumberOfRows
   BiggestHeight = -1
   RowHeight2_1 = RowHeight_1
   If lastRow = 0 Then
      RowHeight2 = 0
      a = GetView(lastRow - 1,0)
      RowHeight2 = a.Top + a.Height + RowLineWidth
   End If
   For I = 0 To NumberOfColumns - 1
      Dim l As Label
      l.Text = Values(I)
      l.Gravity = Alignment
      l.TextSize = FontSize
      l.TextColor = FontColor
      Dim rc As RowCol
      rc.Col = I
      rc.Row = lastRow
      l.Tag = rc

      tbl.AddView(l, ColumnWidth * I, RowHeight2, ColumnWidth_1, RowHeight2_1)
      AdjustHeight (l)
      If BiggestHeight < 0 Then   'first cell
         BiggestHeight = l.Height
         RowHeight2_1 = BiggestHeight
      Else If BiggestHeight < l.Height Then 
         BiggestHeight = l.Height
         Lprev.Height = BiggestHeight
         RowHeight2_1 = BiggestHeight
      Else If BiggestHeight > l.Height Then 
         l.Height = BiggestHeight
      End If
      Lprev = l   'latest cell
   tbl.Height = tbl.Height + BiggestHeight + 2dip 
End Sub
Last edited:


Licensed User
This code works in my project, adjusting whole the row (all labels) height for the text.
I meant, that such auto-adjusting for cell's text would be also useful in your class.


Active Member
Licensed User
Can Table also added to a panel?

The Table is added to an Activity. Would it be possible to add a Table also to panel?


Active Member
Licensed User
Hi Erel,

This is what I get trying to test it out.
Do I have to fill in somewhere to fix it.

Compiling code. Error
Error parsing program.
Error description: Undeclared variable 'subexists' is used before it was assigned any value.
Occurred on line: 233
If SubExists(Callback, Event & "_CellClick") Then


It shouldn't be difficult to show SQL tables using DBUtils.ExecuteMemoryTable

Is this Tableview also to use for Mysql database?


Licensed User
How can I apply the sample code to loading the contents of a SQLite table instead of loading a CSV file. Do I need to convert the table to a CSV file, then load the CSV file as it is shown in this sample? There is a reference to DBUtils.ExecuteMemoryTable, but I have not used that before.
Thank you for any tips or snippets.