B4A Library Grid/Table and ListView Library

This library allows to create easely grids/tables and
from version 2.50
list views too!
Enjoy!
:)

The original post has been moved
http://www.b4x.com/android/forum/threads/grid-library.16381/page-10#post-168452"

Version 2.50 beta
- Added support for multiline rows

Version 2.51 beta
- Bug fixes

Version 2.52 beta
- Added Typeface support for rows and hedaer

Version 2.53
- Added SingleLine property for columns

sample code and usage hints can be found here
http://www.b4x.com/android/forum/threads/grid-library.16381/page-15#post-194602

Version 2.55
- Added object b4aActivityContext

Version 2.56
- Added and modified event hendlers
https://www.b4x.com/android/forum/threads/grid-and-listview-library.16381/page-19#post-297198

Version 2.57
- Added Columns Builders
https://www.b4x.com/android/forum/threads/grid-and-listview-library.16381/page-19#post-299406

Version 2.58
- Bug fixes

Version 2.59
- Added RowHeight for each column
- Added HeaderHeight for each column
https://www.b4x.com/android/forum/threads/grid-and-listview-library.16381/page-19#post-304465

Version 2.60
- Added TouchX() and TouchY()
- Added FirstVisiblePosition() and LastVisiblePosition()
https://www.b4x.com/android/forum/threads/grid-and-listview-library.16381/page-19#post-304905

Version 2.65
- Added Button Columns
https://www.b4x.com/android/forum/threads/grid-and-listview-library.16381/page-19#post-306507

Version 2.67
- Added CellProps event
- Removed PropSetColor / PropSetTextColor
https://www.b4x.com/android/forum/threads/grid-table-and-listview-library.16381/page-19#post-307490

Version 2.71
- Added OnSelectAllow event
- Added selection on row background
https://www.b4x.com/android/forum/threads/grid-table-and-listview-library.16381/page-21#post-347618

Version 2.73
- Added OnRowProps event
https://www.b4x.com/android/forum/threads/grid-table-and-listview-library.16381/page-21#post-349404

Version 2.76
- Fixed dubug log bug
https://www.b4x.com/android/forum/threads/grid-table-and-listview-library.16381/page-21#post-375965

If you like my grid.
You can support the development.


 

Attachments

  • xnGridSample200beta.zip
    3.6 KB · Views: 2,175
  • xnGrid2xx_1.png
    xnGrid2xx_1.png
    77.2 KB · Views: 5,283
  • xnObjects267.zip
    75.7 KB · Views: 917
  • xnObjects272.zip
    87.2 KB · Views: 700
  • xnObjects273.zip
    87.5 KB · Views: 790
  • xnObjects276.zip
    87.2 KB · Views: 1,562
Last edited:

stefanobusetto

Active Member
Licensed User
Longtime User
Yes I've checked and it looks like it can be done!
I can't tell now if i'll add in a future release.

For my reference (call stack):
- getChildAt
- getLocationOnScreen
- getWidth
- getHeight
- getFirstVisiblePosition
- getLastVisiblePosition
 

TheMightySwe

Active Member
Licensed User
Longtime User
Cool, it will be used with PopupMenu library i my case. Don't forget that...

- getFirstVisiblePosition
- getLastVisiblePosition

...needs to be both in Rows and Columns

So maybe,,,

- getFirstVisibleRow
- getLastVisibleRow
- getFirstVisibleColumn
- getLastVisibleColumn

would be a good idea.
 

TheMightySwe

Active Member
Licensed User
Longtime User
Hi again.

I just realized one thing. I dont know if its possible.

But I would love if it was possible to lock one or two of the left columns from scrolling.

If you have many, many columns and many many rows there is hard to se what row you are clicking on.

So in short, it would be lovley if you could lock x columns to the left.
 

TheMightySwe

Active Member
Licensed User
Longtime User
I did a work around.

My table has 37 columns, so I diveded it up a bit, but it sure would be nice to be able to have it all in one grid.
 

Taha

Member
Licensed User
Longtime User
I wonder that no one asked about xnGrid events. By tests I found Select by now. Could you please, describe events and handling. Thanks.
 

TheMightySwe

Active Member
Licensed User
Longtime User
B4X:
Sub Items_xnGrid_Select   Or  Items_xnGrid_Long_select

    Dim Row,Col As Int
    Dim Value As String

    Row = Items_xnGrid.RowSelected
    Col = Items_xnGrid.ColSelected

    Value = Items_xnGrid.GetValue(Row,Col)

    '[Do Stuff]

    Items_xnGrid.SetValue(Row,Col, Value)

End Sub
 

stefanobusetto

Active Member
Licensed User
Longtime User
you have also
..._header_click event
and you can get the header clicked using
the HeaderClicked() function

:)
 

Taha

Member
Licensed User
Longtime User
Thanks!! Another thing - how to use column.PositionSet() to fit bitmap? On some phones the bitmap may fit into a cell, on others - no.
 

stefanobusetto

Active Member
Licensed User
Longtime User
PositionSet is used to create a multiline row grid
you can see post # 289
Example : cc(4).PositionSet ( 1 , 3 , 2 , 1 ) means
the column cc(4) wil be placed
BELOW column 1
RIGHT_OF column 2

If you want to fine tune the position of an image in a cell you have :
cc(4).HeaderIconLeft = 1dip
cc(4).HeaderIconTop = ...
cc(4).RowIconLeft = ...
cc(4).RowIconTop = ...
where cc(4) is an xnGridCol
:)
 

informatica_iberteam

New Member
Licensed User
Longtime User
Hello stefanobusetto, i am observing that after use Grid.CursorAppend ( AuxCursor ) or Grid.RowAppend there is a memory loss. Use Version 2.53

Grid.RowsDelete

Grid.GridClear


AuxCursor = BBDD.ExecQuery ( SQL )
Grid.CursorAppend ( AuxCursor )

OR

If AuxCursor.RowCount > 0 Then

For r = 0 To AuxCursor.RowCount -1

AuxCursor.Position = r


Grid.RowAppend ( Array As String .....
Next
End IF


AuxCursor.Close

Anyone know the cause?.

Thank you
 

informatica_iberteam

New Member
Licensed User
Longtime User
Hi Stefanobusetto, I detect no error just memory consumption in the task manager does not appear.
I have an application with TabHost, after entering and leaving the tab where the Grid asked several times,
and check the consumption in the task manager memory usage of my App I see that progressively increases reaching several megabytes.
The number of rows available is very small between 1 and 30 rows up.
The code is:
' **************************************************************************
Sub TabHost1_TabChanged

Select Case TabHost1.CurrentTab
Case 0
......
Case 1
.......
Case 2
.......
Case 4 ' Grid
Grid_Crear
End Select


End Sub

' **************************************************************************
Sub Grid_Crear
If Grid.IsInitialized =False Then
Grid.Initialize("Grid")
Grid.HeaderHeight = 30dip
Grid.RowHeight = 50dip
Grid.HeaderTextSize = 13
Grid.RowTextSize = 13
Etc . . . .
End If

Grid_fill_cursor
End Sub

' **************************************************************************
Sub Grid_fill_cursor( )
Dim AuxCursor As Cursor
Dim SQL As String

SQL="Select CODIGO, NOMBRE_ORI, POBLACION_ORI, HORA_MD||'-'||HORA_MH||'/'||HORA_TD||'-'||HORA_TH AS HORARIO, ESTADO FROM PRU WHERE ESTADO IN ('N', 'P') "

AuxCursor = BBDD.ExecQuery ( SQL )

Grid.RowsDelete
Grid.GridClear


If AuxCursor.RowCount > 0 Then

LblNReco.Text =AuxCursor.RowCount

For r = 0 To AuxCursor.RowCount -1
AuxCursor.Position = r
Grid.RowAppend ( Array As String ( AuxCursor.GetInt("CODIGO") , AuxCursor.GetString("NOMBRE_ORI") , AuxCursor.GetString("POBLACION_ORI") , AuxCursor.GetString("HORARIO")) )
Next
Grid.GridCreate2 (False)
Else
Msgbox("No existen datos.","Aviso")

End If


AuxCursor.close

End Sub
 

stefanobusetto

Active Member
Licensed User
Longtime User
I usually initialize all the views (xnGrids included) in the Activity_Create.
Then i clear/add/delete rows from the xnGrids.
You can try but i do not think this is the problem.
If there is a problem at all.
B4A is java and java has a garbage collector.
It means you never destroy any object,
the garbage collector destroys the objects when needed.

The xnGrid uses a java list to hold the data and an android listview to display the items.
I've implemented an adapter so the views of each row are recycled when needed.
Only the views of the rows that are visible are created.

Everything is destroyed (again) when needed but i can't tell you when.
Android is unix/linux. And usually a unix machine uses as much ram as possible.

I know i'm quite obscure and vague.
And obviously i'll try to figure out if there is a problem.
But there are many memory allocation and object management
policies i have no knowledge or control of.

What i can tell for sure instead is that i use this grid in at least 15 app in a production environment since 2012.
I have more the 50 android devices and i've never experienced low memory problems.

Thanks for your post.
You've given me something to think about.
:)
 

David Hawkins

Active Member
Licensed User
Longtime User
Hi Stefano

Thank you for the reply, can you tell me if there is any time line for this to happen?

Regards

David
 
Top