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
    xnGridSample200beta.zip
    3.6 KB · Views: 2,737
  • xnGrid2xx_1.png
    xnGrid2xx_1.png
    77.2 KB · Views: 5,962
  • xnObjects267.zip
    xnObjects267.zip
    75.7 KB · Views: 1,494
  • xnObjects272.zip
    xnObjects272.zip
    87.2 KB · Views: 1,280
  • xnObjects273.zip
    xnObjects273.zip
    87.5 KB · Views: 1,368
  • xnObjects276.zip
    xnObjects276.zip
    87.2 KB · Views: 2,171
Last edited:
hi Volker
"Array As String(aSpalten)" returns an arry of 1 item

Code:
Sub bt_test_click
Dim col As Int
col = 4

Dim kZeile  As String
kZeile  = "a;b;c;d"

' split into fZeile() 
Dim fZeile() As String
fZeile = Regex.Split(";", kZeile )

' copy from fZeile() to aSpalten()
Dim aSpalten(fZeile.Length) As String
For i = 0 To fZeile.Length - 1 
    aSpalten(i) = fZeile(i) 
Next

' ok 4 items
Log ( fZeile.Length )

' ok 4 items
Log ( aSpalten.Length )

' copy to aResult() 
Dim aResult() As String
aResult = Array As String ( aSpalten )

' only 1 item
Log ( aResult.Length )

Log ( "----------------" )

' --------------------------
Dim col As Int
col = 4

Dim kZeile  As String
kZeile  = "a;b;c;d"

' split into fZeile() 
Dim fZeile() As String
fZeile = Regex.Split(";", kZeile )

If fZeile.Length = col Then
   ' copy to aResult() 
   Dim aResult(fZeile.Length) As String
   For i = 0 To fZeile.Length - 1 
       aResult(i) = fZeile(i) 
   Next
   
   ' ok 4 items
   Log ( aResult.Length )

End If

End Sub

i think you can use the follwing code
Code:
Dim Tr As TextReader
Dim kZeile As String
Dim aSpalten(col) As String col is a known index

Tr.Initialize(File.OpenInput(File.DirAssets, "demo.txt"))
kZeile = Tr.ReadLine
Do While kZeile <> Null
Dim fZeile() As String
If kZeile.Length > 0 Then
    fZeile=Regex.Split(";", kZeile)
    If fZeile.Length = col Then
        Tabelle.AppendRow(fZeile) 
    End If
End If   
kZeile = Tr.ReadLine   
Loop
Tr.Close
:)
 
Hallo Stefano,

coming up a new question.

I try to copy selected row´s in a new grid.

It is very slow and I didn´t find anything to copy
a row directly to the new grid.
watch my code , perhaps there is another solution....

For i = 0 To Tabelle.RowsSelected.Length - 1
Dim kZeile As String
Dim sZeile() As String
For p = 0 To Tabelle.ColCount - 2
kZeile= kZeile & Tabelle.GetValue(Tabelle.RowsSelected(i),p) & ";"
Next

kZeile = kZeile & Tabelle.GetValue(Tabelle.RowsSelected(i),p)
sZeile =Regex.split(";", kZeile)
Tabelleselk.AppendRow(sZeile)
Next

Tabelleselk.GridCreate2(False, True)


kind regards Volker
 
hi Volker
how many rows and cols are there in the destination table?
what do you mean for slow? 1sec , 2sec , ...

if you prefer you could also avoid to store the data
of the source row in a delimited string you can use a map
or an array directly and then call then MapAppendRow or
AppendRow methods

you could also avoid to compute the selected row for each
iteration of the loop
Code:
rs = Tabelle.RowsSelected(i)
For p = 0 To Tabelle.ColCount - 2
kZeile= kZeile & Tabelle.GetValue(rs,p) & ";"
Next
:)
 
map

Hallo Stefano,

thanks for your reply.
Now it is much faster.
I process a grid 20 * 500 elements
120 selected, now 2 seconds in the new grid

Please can you show how map is working with
your grid. (special copy a row and append in new grid)
;);) I don´t see the tree in the forest...

kind regards

Volker
 
if you have for example, a grid with 4 columns
Code:
   Dim cc(4) As xnGridCol

   cc(0).Initialize2 ( "Cod." , "cod" , 40dip , Gravity.LEFT )
   gg.AppendCol ( cc(0) )

   cc(1).Initialize2 ( "Des." , "des" , 120dip , Gravity.LEFT )
   gg.AppendCol ( cc(1) )

   cc(2).Initialize2 ( "Grp." , "grp" , 60dip , Gravity.LEFT )
   gg.AppendCol ( cc(2) )

   cc(3).Initialize2 ( "Other" , "other" , 100dip , Gravity.LEFT )
   gg.AppendCol ( cc(3) )

you can add a row using AppendRow
Code:
gg.AppendRow ( Array As String ( "1" , "1" , "1" , "1" ) )
gg.AppendRow ( Array As String ( "2" , "2" , "2" , "2" ) )
the array you pass to the AppendRow must have 4 elements
because the grid has 4 columns

but if you use MapAppendRow
Code:
Dim m As Map
m.Initialize
m.Put("cod","a")
gg.MapAppendRow(m)
m.Initialize
m.Put("des","b")
gg.MapAppendRow(m)
you can pass to the MapAppendRow a map
with less then 4 elements
and you can set the value by name!

:)
 
Hello,

is it possible to jump to a row? With SelectRow it is possible to select the row, but the grid doesn't scroll to the selected row.

Thanks
 
there are 2 methods
ScrollDown
ScrollUp
to scroll the grid to the first row or
to the last row
that's what you need?
 
Hello, Stefano!
I can't to compile your sample.
I use B4A v2.52, xnObjects v1.63
B4A shows this error:
Parsing code. 0.01
Compiling code. 0.03
Compiling layouts code. 0.00
Generating R file. Error
AndroidManifest.xml:22: error: Error: String types not allowed (at 'configChanges' with value 'keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize').
 
there are 2 methods
ScrollDown
ScrollUp
to scroll the grid to the first row or
to the last row
that's what you need?

I know these 2 methods, but I don't want to scroll to the top or bottom. I just want to scroll to a certain position.
For example: my grid has 100 rows. Now i can select row 50 with the selectrow method. This only selects row 50, but does not scroll to row 50. So I cannot see the highlighted row until I scroll there with my finger.
It would be nice to jump to that row and show it.
 
Hi.

Firs of all sorry for may bad english.
We are trying your grid.
We asking if is posible align header and rows with diferent horizotal position.
We use initiazed2 center_horizontal in some columns, in another columns use left, but we want center_horizontal all columns of header and depending of type of data, align center, left or right rows.

Is posible, formating numbers in one column?

Thanks.
 
@discorez
i've compiled with no problems the sample project
with xnObject 1.67
i use jdk1.6.0_30
if you want i can send the sample project again
please let me know
:)
 

Attachments

@aviario

don't worry for your english
mine is not much better :)

there is no way to set a gravity of the header
and a different one for the rows
this is indeed a nice feature i'll add to a furure release

as for the number format
the content of a cell is text you can format
as you like

:)
 
@aviario

don't worry for your english
mine is not much better :)

there is no way to set a gravity of the header
and a different one for the rows
this is indeed a nice feature i'll add to a furure release

as for the number format
the content of a cell is text you can format
as you like

:)

Thanks for your reply

Another question. Is posible hidden cols?

Thanks again
 
Back
Top