B4A Library Grid/Table and ListView Library

Mahares

Expert
Licensed User
Longtime User
@Stefano: After installing the xnObjets library, I tried the sample code you had, but I got this error:

Compiling code. Error
Error compiling program.
Error description: Cannot cast type: {Type=Double,Rank=0} to: {Type=String,Rank=1}
Occurred on line: 155
If gg.InsertRow ( Array As String ( "new" , "new" , "new" , "new" ) , 3) Then
Word: 3


Let us assume you help me overcome the eror. Can I apply this to displaying a SQLite table with 50 to 60 columns and something like 5000 records on a fast device without locking up or taking too much time to load? I have not found anything that allows me to display large tables in a spreadsheet like format with many fields (columns) and several thousands records in a quick manner, except if I filter the data.
I hope you have an answer, particularly with your vast database knowledge.
Thanks
 

stefanobusetto

Active Member
Licensed User
Longtime User
sorry pal
i was not clear in my previous post
i have switched param order of some methods
try
B4X:
If gg.InsertRow ( 3 , Array As String ( "new" , "new" , "new" , "new" ) ) Then

as for the database it quite a huge one!
there are no limits in the code (max rows, max columns, or something like this)
if you try and get very long loading / creating times
you could send me the code and the sample database
so i can debug it and see if i can improve performance
 

stefanobusetto

Active Member
Licensed User
Longtime User
@mahares
i've been thinking a lot to your request
1) the grid 50 columns x 5000 rows doesn't sound me right
such a grid creates (obviously) 255000 views
wich is quite a lot not only for android
2) a also don't belive a user is going to scroll
such e huge grid
if you can post some details
and if you like a can try to figure out an alternate
way to do the task
 

mc73

Well-Known Member
Licensed User
Longtime User

I absolutely agree on whether it is appropriate to have such a large view. I didn't have time yet to check your library, but from what I've found, a webView may handle such big data areas. Perhaps you've already thought about this? Just an idea from a previous post, here
 
Last edited:

Mahares

Expert
Licensed User
Longtime User
@stefano: Your xnGrid library is very good. I did write an application using your library where I tried to import an SQLlite database where one table had close to 3000 records. The device locked up. Therefore, what I did is created a button above the grid where you can navigate the records say, 100 records at a time instead of loading all 3000 records at once. I am still stuck on creating a button that goes backward say 100 records at a time. I am working on the logic, but have not figured it out yet. I sent you a personal message.
@mc73: I am going to check your webview sample also to see if I can load all 3000 records with 54 columns (fields). With the speed and memory of the devices today, there is no reason why 3000 records could not be uploaded into memory. Imagine if you are working with Microsoft Access with a much slower PC, you can open a table with hundred thousands records. It is and Android limitation that needs overcome. By the way, are you related to mc squared? Just kidding! You are blessed with a lot of knowledge.
Thanks
 
Last edited:

mc73

Well-Known Member
Licensed User
Longtime User

I'm a physicist
True, there shouldn't be such limitations. I noticed that while such processes are running (the loop to populate that 'many' data), android gets to use 17mb. This is not something quite logical, in my opinion. But, guess, we have to find alternatives.
 

stefanobusetto

Active Member
Licensed User
Longtime User
I'm NOT a physicist!


But may be i have a couple of ideas.
Even if the grid has not been developed for such a huge amount of data
something can be done.

The grid loads the data in a memory structure (an array for now)
and the "paints" the grid creating rows=layouts and columns=textviews.

First idea
Every time a row is added the array must be resized.
But data could also be added in some sort of bulk mode.
Thus allowing to dimension the array only one time.

Second one
The grid uses a memory structure to store and views to display
(i've designed it in this way to allow in-place editing in the future).
But adding a flag i could use the textviews to store the data too.

Third one
Not mine (yust an improvement of mahares one)
The grid could load all the data in the memory structure and
show "a page" of them.

First, second third or a mix?
May be none!
Sure to make the choice a need at least 2 data.
1) Load time of the data form the database into the memory table.
2) Creation time of the 250000 textviews
I'd also like to know the maximum time mahares can wait.

Waiting for the database (if possible).
If not ...
It's ok anyway.

Be patient!
My response times are slow!
 

mc73

Well-Known Member
Licensed User
Longtime User
I think the idea of showing a "page" is quite good. After all, isn't this what happens whenever we use phpAdmin for example?
One thing I could add, is IF we have the possibility to capture the scroll event in such a way that we change rows' contents dynamically. This way, we shall only need a fixed area of labels, while replacing their contents accordingly.
 

molder26

Member
Licensed User
Longtime User
Hi stefano, congratz for this great grid!
I am using your lib in a project and i want select view the last row created, something like fullscroll, it's possible now?
Regards
 
Last edited:

stefanobusetto

Active Member
Licensed User
Longtime User
New version 1.50
Allows set and get values using column/field names
- GetValue2 ( int Row , String Field )
- SetValue2 ( int Row , int Col , String Value )

Added also long_select event
B4X:
Sub gg_long_select
' **************************************************************************
' handling the long single selection
' **************************************************************************
If gg.IsMultiselect = False Then
   Msgbox ( "LONG : value of the first column = " & gg.GetValue  ( gg.RowSelected , 0     ) , "row selected = " & gg.RowSelected )
   Msgbox ( "LONG : value of the first column = " & gg.GetValue2 ( gg.RowSelected , "cod" ) , "row selected = " & gg.RowSelected )
End If
End Sub
 

stefanobusetto

Active Member
Licensed User
Longtime User
@mahares
i'll post a new version of the grid with bulk methods
here is the code i've used for testing with your data
B4X:
   ' **************************************************************************
   ' Below fill the grid 
   ' **************************************************************************   
   Dim t0 As Long
    t0 = DateTime.Now
   Log ( "start: " & DateTime.Time(t0) )

    gg.GridClear
    gg.DeleteRows  'clear table to prepare for next 100 records
   
   
   Dim num_first As Int
   Dim num_last As Int
   num_first = 800
   num_last = num_first + 400

    gg.BulkSetLength(num_last-num_first+1)  
     
   If False Then
       gg.BulkCursorAppend ( Cursor1 , num_first , num_last )
   Else    
       For i = num_first To num_last 'RecCount-1
         Cursor1.Position = i 
          gg.BulkCursorSetRow ( i - num_first , Cursor1 )
       Next
   End If
    
    gg.GridCreate2 ( True , True )   'scroll vertically and horizontally 7/1/12
   lblCount.Text=RecCount& " of " & RecCount

   Dim t1 As Long
    t1 = DateTime.Now
   Log ( "stop: " & DateTime.Time(t1) )
   
   Log ( "elapsed : " & ( t1 - t0 ) )
i've also written the append in two different ways
surely i've experienced at least a 25% of improve in load times
but i've not been able to load the full dataset!
so i've added support to load set of records
that's all
sorry
 

Mahares

Expert
Licensed User
Longtime User
@stefano: I will await your complete changes. If you think the only way to speed it up is to break the load of data in chunks or records, well as I mentioned to you, I did that and it works well. I load 100 records at a time. It takes about 3 seconds to load 100 records on a Droid Razr. If you can load a lot more rows and stay within the 3 or 4 seconds, that would be great. Beyond that, people lose interest.
Thanks
 

molder26

Member
Licensed User
Longtime User
@stefano: i want select the last row in the grid.
I try use grid.selectrow(grid.RowCount-1), only select the row and i need do it visible.
The idea is make visible the last row. The grid have 400 row.
Thanks in advance!
 
Last edited:

Mahares

Expert
Licensed User
Longtime User
Here is a workaround I did to show the last row content since I could not scroll to it programmatically. I hope Stefano will offer us a better way.

B4X:
   gg.GridCreate2 ( True , True )   'scroll vertically and horizontally , gg is the grid
   gg.selectrow(gg.RowCount-1)
   gg_select


Sub gg_select     'Selected record
        Dim RecSelected As Int
      RecSelected=gg.RowSelected +1
        Msgbox ( "Field1= " & gg.GetValue ( gg.RowSelected , 0 ) & CRLF _ 
      & "Field2 " & gg.GetValue ( gg.RowSelected , 1 ) & CRLF _ 
       & "Field3= " & gg.GetValue ( gg.RowSelected , 2 ) & CRLF _ 
       & "Field4= " & gg.GetValue ( gg.RowSelected , 3 ) & CRLF _ 
       & "Field5= " & gg.GetValue ( gg.RowSelected , 4 ) & CRLF _ 
       & "Field6= " & gg.GetValue ( gg.RowSelected , 5 ) & CRLF _ 
       & "Field7= " & gg.GetValue ( gg.RowSelected , 6 ) & CRLF _ 
, "Record selected = "  gg.RowCount )
End Sub
 

molder26

Member
Licensed User
Longtime User
@mahares: thank you, but i was looking move the scroll to bottom. I will wait a new update of the lib to do it
Regards
 

giannimaione

Well-Known Member
Licensed User
Longtime User
upper right

ciao Stefano
compare un rettangolo NERO in alto a dx.. dove sbaglio?
sul form/layout NON ho altri oggetti

see the upper right
B4X:
Dim grdScheda As xnGrid
Dim tblScheda(3) As xnGridCol

bla
bla
bla
   grdScheda.Initialize("x")
   tblScheda(0).Initialize("Data","Aammgg",25%x)
   tblScheda(1).Initialize("Descrizione","Desc",50%x)
   tblScheda(2).Initialize2("Importo","Importo",25%x,Gravity.RIGHT)
   grdScheda.AppendCol(tblScheda(0))
   grdScheda.AppendCol(tblScheda(1))
   grdScheda.AppendCol(tblScheda(2))
bla
bla
bla

   grdScheda.AppendRow(Array As String(Aammgg,Desc,Importo))

   grdScheda.HeaderTextSize = 15
   grdScheda.RowTextSize = 18
   grdScheda.RowHeight = 65dip
   grdScheda.HeaderColor=Colors.Blue
   grdScheda.SelectedOddColor=Colors.Yellow
   Activity.AddView (grdScheda , 0 , 0 , 100%x , 100%y)
   grdScheda.GridCreate2(False,True)
 

Attachments

  • DEMO.jpg
    40.4 KB · Views: 334

stefanobusetto

Active Member
Licensed User
Longtime User
try
B4X:
tblScheda(2).Initialize2("Importo","Importo",25%x,Bit.Or ( Gravity.RIGHT , Gravity.CENTER_VERTICAL )
 

Mahares

Expert
Licensed User
Longtime User
Since the revision of the library includes some new functions, could you please explain the syntax of the following perhaps with a sample, so we can implement them:

B4X:
gg.BulkCursorAppend
gg.BulkCursorSetRow
gg.BulkCursorSetRow
gg.BulkSetLength
gg.BulkSetRow

Also, a great improvement suggestion to the library would be a fastscroll vertical button like in fast scrolling listview. gg.FastScrollEnabled=True The horizontal scroll is good. The vertical scroll is a little sluggish.
Thank you for a great product.
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…