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

An improved version of this class is available here: http://www.b4x.com/forum/additional...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.

SS-2012-07-04_10.38.01.png


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.b4x.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.
 

Attachments

  • Table.zip
    14.9 KB · Views: 7,615
Last edited:

B4AJunkie

Member
Licensed User
Longtime User
:icon_clap:
Thanks Klaus.
That was it.
I set SV.enable to false. That did'nt work. Why I did not try to set the visibility to false as in the line above, i don't know.

Sometimes it needs just a slap on the backhead.

Thank you!
 

yuhong

Member
Licensed User
Longtime User
Attached you find a modified version of the Table class with horizontal scrolling with the ScrollView2D object and columns with different widths.

Best regards.

EDIT: 2012.07.15
Updated the project with Erels version V1.11 fixing the grey line problem.

must be call setColumnsWidths, else don't show cell.

table:V1.11_2d
android 2.3.3 api 10
b4a:2.22
 
Last edited:

ajk

Active Member
Licensed User
Longtime User
Long Click

I call:
Private Sub Cell_Click
Dim rc As RowCol
Dim l As Label
l = Sender
rc = l.Tag
SelectRow(rc.Row)
If SubExists(Callback, Event & "_CellClick") Then
CallSub3(Callback, Event & "_CellClick", rc.Col, rc.Row)
End If
Log("short tab" )
End Sub

with:

Sub Table1_CellClick (Col As Int, Row As Int)
Log("main short " )
Activity.Title = Table1.GetValue(Col, Row)
End Sub

and works ok.

How to catch events for Long Clicks for table cell or header?


Reply:

pair:
Private Sub Cell_LongClick
Dim rc As RowCol
Dim l As Label
l = Sender
rc = l.Tag
SelectRow(rc.Row)
If SubExists(Callback, Event & "_Cell_LongClick") Then
CallSub3(Callback, Event & "_Cell_LongClick", rc.Col, rc.Row)
End If
Log("long tab" )
End Sub

and:

Sub Table1_Cell_LongClick (Col As Int, Row As Int)
Log("main long")
End Sub

works OK
 
Last edited:

klaus

Expert
Licensed User
Longtime User
This routine in the Table Class:
B4X:
Private Sub Cell_LongClick
    Dim rc As RowCol
    Dim l As Label
    l = Sender
    rc = l.Tag
    SelectRow(rc.Row)
    If SubExists(Callback, Event & "_CellLongClick") Then
        CallSub3(Callback, Event & "_CellLongClick", rc.Col, rc.Row)
    End If
End Sub
And in the Activity code:
B4X:
Sub Table1_CellLongClick (Col As Int, Row As Int)
    Log("CellLongClick: " & Col & " , " & Row)
    Activity.Title = Table1.GetValue(Col, Row)
End Sub
Best regards.
 

Informatix

Expert
Licensed User
Longtime User
I have been looking for something like this Tableview for some time.
Regrettably the provided example code crashes due to Java OutofMemory errors (as shown in the B4A logs).

I tried to open a 4.8 Mbytes CSV file with about 30,000 entries (and data in 12 columns).

I often get OutofMemory errors on a number of devices (probably due to Android constraints and not B4A). Hopefully Erel has some more tips how these errors can be overcome and how a "500,000" fields Table can indeed be used with this Tableview.

It is disappointing that Android has memory size problems (I don't understand why because most devices have at least 1 GB free memory). Opening high resolution bitmaps (larger than about 150kB) for example is also often not possible.

In a few days, I'm going to sell a set of classes and libraries allowing to handle very big lists and tables. With it, the Out Of Memory Exception will be something from the past. You can look at the screenshots of the beta-test here.

About the OOM, this occurs when you exceed the memory allocated to your application. And this memory (named heap memory) ranges from 16 MB to 48 MB on the current devices.
 

ajk

Active Member
Licensed User
Longtime User
How to hide rows by custom criteria (eg. contens of cell)
I try to change row height before
AddRow(ROW)

but after that I need to use
Table1.SetColumnsWidths to set proper columns widths.
Moreover scroll subs needs to be rewritten.

Any simple solution?
 

Informatix

Expert
Licensed User
Longtime User
The new UltimateListview by Informatrix looks very promissing.
Can the data be sorted?

The ULV has a different philosophy from the listviews and custom listviews which you are accustomed. You do not load data into it, you provide them in real time (like Java users do with some adapters). So all the content management is done outside of the list engine.
That being said, sorting is not a problem. This is possible with a single command for Lists, Arrays and database records.

Where will you release it (via this forum or via the Play Store)?

In the library forum, before the end of this week I hope. The product is finished but I want to optimize three functions. Their optimized version produces a strange result (there's a bug outside of my code, with drawables, and I have to find a workaround).

I wonder why Google has made these contraints in Android. Any smart phone nowadays has at least a couple of Gbytes RAM....

Android has been designed when the RAM on phone devices was much lower than today. And, as you can see, that does not prevent a lot of developpers from doing fantastic apps.

I do hope this will be improved in future Android versions. Does anyone know if OOM is less likely in "Jelly Bean"?

It's related to the system architecture, so that probably won't change a lot in the future versions.
On a PC, you don't care if a program takes all memory for itself. On a phone, where some apps must continue to run in the background and may need quickly some memory (like the app managing the phone calls), it's a very different problem.
 

Informatix

Expert
Licensed User
Longtime User
Just to say thank you to Informatix for your detailed reply to my questions.
It is very helpful.

The problem I have is that the App that I am making has nearly 1000 functions! It will be called "ARTI" (similar to my Windows version on ARTI: Interactieve software met kunstmatige intelligentie!) Almost any mobile phone feature can be activated and controlled by voice.

Regrettably, the OOM problem keeps bothering me. E.g. my app crashes in auto-load mode (i.e. when the phone is switched on). I use a B4A services routine, provided by Erel. Somehow the phone is using more memory during start-up.

The only known methods to bypass the heap memory limitation is to use OpenGL textures (not really helpful for not-game apps) or the NDK to create (or reuse) libraries written in another language (usually C or C++). In these libraries, you manage yourself the memory allocations.
I strongly advise to not use the LargeHeap option. The Google engineers said many times you should never use it. And that's not available on Android versions < 3.
As you can see, all of this is a bit technical...
 

yuhong

Member
Licensed User
Longtime User
Attached you find a modified version of the Table class with horizontal scrolling with the ScrollView2D object and columns with different widths.

Best regards.

EDIT: 2012.07.15
Updated the project with Erels version V1.11 fixing the grey line problem.

how don't horizontal scrolling table?
:signOops:
 

msawada

Member
Licensed User
Longtime User
Having major issue (maybe bug) with TableView modified by Klaus

Basically, when I load data programaltically to the Klaus' horizontal scroll, I get a table show up, however, when I click on a row, it hightlights bt also change the values in that whole row to those of another row, usually the last one in the table, likewise, click on another and the change ocurrs again for the newly selected, row. I can't figure out why. The examples provided work perfectly, but when I modify them to add row data as string arrays constructed in the code then this issue keeps happening, it is easy to reproduce, here is an example, modified from Klaus's 2D code, below, if you run it ensure to dlownload Klaus' modification in Comment 22 of this forum and replace the code in the main with this:

ANY help would be most appreciated

B4X:
Sub Process_Globals
   
End Sub

Sub Globals
   Dim Table1 As Table
End Sub

Sub Activity_Create(FirstTime As Boolean)
   Table1.Initialize(Me, "Table1", 40)
   Table1.AddToActivity(Activity, 0, 0dip, 100%x, 50%y)   
   
   'just make onger headerrow
   Dim i As Long
   Dim hrow(40) As String
   Dim colwidths(40) As Int
   For i = 0 To 40-1
      hrow(i)= "C" & i
      colwidths(i)=120dip
   Next
   'set header with array
   Table1.SetHeader(hrow)'Array As String("Col0", "Col1", "Col2", "Col3"))
   
   
   Dim valx(40) As String
   For i = 0 To 500-1
       For k = 0 To 39-1
         valx(k)=Rnd(0,100)
      Next
      'add aray ofrandom numbers
      Table1.AddRow(valx)'Array As String("Row: " & i, "ccc", "ddd", "eee"))
   Next
   
   Table1.SetColumnsWidths(colwidths)
   
   
End Sub

Sub ClearAll_Click
   Table1.ClearAll
   
End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

Sub Table1_CellClick (Col As Int, Row As Int)
   Log("CellClick: " & Col & " , " & Row)
   Activity.Title = Table1.GetValue(Col, Row)
End Sub

Sub Table1_HeaderClick (Col As Int)
   Log("HeaderClick: " & Col)
End Sub
 

msawada

Member
Licensed User
Longtime User
Having major issue (maybe bug) with TableView modified by Klaus

thanks Klaus, I've attached zip of the complete file built in B4a 2.22. Hopefully you will see the issue right away when loding the project in debug mode. I used a Xoom tablet for testing.
thanks
Mike
 

Attachments

  • urbanrat.zip
    15.1 KB · Views: 262

klaus

Expert
Licensed User
Longtime User
You must Dim valx inside the first Loop.
B4X:
For i = 0 To 499
  Dim valx(40) As String
  For k = 0 To 39
    valx(k)=Rnd(0,100)
  Next
  'add aray ofrandom numbers
  Table1.AddRow(valx)'Array As String("Row: " & i, "ccc", "ddd", "eee"))
Next
Best regards.
 

msawada

Member
Licensed User
Longtime User
Having major issue (maybe bug) with TableView modified by Klaus

Thanks very much Klaus for the quick reply and fix .:). I don't readily see why that works. Couldn't an array like "valx(40) as string" be declarable anywhere, even in the main declarations or the general section, since it gets reused and reinitialized each time the loop reiterates over 0 to 39 - thus re-filling it and then adding it to the tableview row? I'm somewhat confused. any thoughts or specific answer?
 
Top