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,192
  • xnGrid2xx_1.png
    xnGrid2xx_1.png
    77.2 KB · Views: 5,310
  • xnObjects267.zip
    75.7 KB · Views: 932
  • xnObjects272.zip
    87.2 KB · Views: 711
  • xnObjects273.zip
    87.5 KB · Views: 803
  • xnObjects276.zip
    87.2 KB · Views: 1,578
Last edited:

stefanobusetto

Active Member
Licensed User
Longtime User
Hi COBRASoft,
Many of the features you wish are in my wishlist too.
Tanks for the suggestions
 

stefanobusetto

Active Member
Licensed User
Longtime User
You are welcome!
:D

TT.Initialize ( Array As String ( "year" , "num" , ... ) )

GG.Initialize("gg")

Dim c(...) As xnGridCol
c(0).Initialize ( "Year" , "year" , 70dip )
c(1).Initialize ( "Num." , "num" , 70dip )
...

For i = 0 To ...
GG.Columns.Add ( c(i) )
Next

GG.RowHeight = 40dip
Activity.AddView ( GG , 10dip , 50dip , 300dip , 300dip )

Dim qq As Cursor
qq = db.ExecQuery ( "SELECT year , num , ... FROM .." )

Dim i As Int

For i = 0 To qq.RowCount - 1
qq.Position = i

Dim Record As Map
Record = CursorToMap ( q )
TT.AppendFromMap ( Record )
Next

GG.GridCreate ( TT )
 

Harris

Expert
Licensed User
Longtime User
did i forget something?
Can you also explain what the meaning and use is for each property of each object (ie. gg.ba, gg.RowStandard, gg.<clinit>)?


You are correct, my bad. Fields declared in xntable and not displayed are updatable.
However, when I update a "displayed" field with a new value, I can not seem to get the grid to show this "new" value in the grid??? Need a refresh row function or something?


Scrolling the list (grid) seems slow and interupted (at times). The row select event could use a long_click event (select_ItemLongClick) to avoid attempting to scroll from - as opposed to - selecting a row. You can see when placing your finger to scroll the grid, it fires the select event, inadvertantly at times. I prefer to use the long_click event in scrolling situations. That way you KNOW the user is selecting a row for further action.


The "Zen of Android" is not something that the oldie (old guy like me) can grasp easily. I have too many pre-concieved habits and notions of past experiences. Fortunately, I have a huge community to teach me - in B4A. The people who can help find a solution to your problem are a click away. In many situations, the problem has been asked, answered and solved - BUT try and find it on your own (you have to know what the search engine needs). These people point you in the right direction (link) or specifically resolve it.

The point is, don't be afraid to ask for help. Myself, I spend hours trying to resolve something, in my own code, before I humble to asking someone for advice.... - my nature. My day job is to resolve someone body elses code - without any knowledge of what/how they coded. QA is not fun.

Thanks again...
 

stefanobusetto

Active Member
Licensed User
Longtime User
I think the problem with the scroll is due to the 2 scroll views.
The outer one is horizontal and the inner one is vertical.
So if you move the finger not perfectly straight ...
I've experienced the behaviour you describe. I'll try the long click you suggest.

Here are the properties
RowCount / ColCount : number of rows / columns

HeaderHeight : Height of the header
HeaderColor : Background color of the header
HeaderTextSize : Text size of the font of the header

RowHeight, RowOddColor, RowEvenColor and getRowEvenColor : the same but for the rows ( the color of the odd rows can by different from the color of the even ones )

RowSelected : the index of the selected row
RowsSelected : the indexes of the selected rows ( the new library will be on line tomorrow )

Multiselect : the grid allow to select multiple rows ?

SelectedOddColor / SelectedEvenColor : colors of the selected row

That'all ... for now!
Tanks for your offer for help.
:)
 

Harris

Expert
Licensed User
Longtime User
Maybe COBRASoft could provide some code examples from his effort to help you with yours, if it's not infringing.

Sounds like he has one heck of a grid in development.

This is all real promising.
 

COBRASoft

Active Member
Licensed User
Longtime User
@Harris: unfortunately, I can't give code of my grid (propriety stuff and such). But I'm happy to give guidelines for specific parts and hints how to do some of my stuff. I'm happy to share my suffering experiences too ;).

E.g.: the 2-way scrolling is a problem. I 'fixed' it by letting the horizontal scroll being done on the column headers. If the total width is 100% of the grid or less, I don't even place a horizontal scrollview. This way, a horizontal scroll can be placed as a 'columntype'.

Watch out for placing a scrolllview on a scrollview. Android messes things up and scrolling becomes 'ugly'. 1 horizontal scroll and 1 vertical scroll, that's it, not more. A neat trick to fix this could be using a slider view for the horizontal scrolling beneath the grid. I've tried it, worked, but you lose precious screen space this way.
 

Harris

Expert
Licensed User
Longtime User
@COBRASoft: No prob.. I see now why my horizontal and vertical scroll is so sticky.
 

Harris

Expert
Licensed User
Longtime User
stefano,

Hows the lib coming. It does offer a very simple way to use a grid.

Perhaps include a property to turn on/off horizontal scroll when not required. This would improve the vertical scroll considerably.

It needs to refresh a cell (row) when a value has changed.

Thanks
 

stefanobusetto

Active Member
Licensed User
Longtime User
I was thinking to make some structural changes. Yust put the xntable inside the grid to allow sincying. Allow inserting and deleting of rows and YES handling the horizontal scrolling with some kind of gesture on the header. Since this requires some code quite complex involving gestures and animations as a first step i'm going to add a flag to disable the horizontal scroll as you suggest.
Posting soon. I hope.
Any other ideas?
I'd like to know if someone is using the grid in any application.
:)
 

Harris

Expert
Licensed User
Longtime User
I am trying to use it in mine, but it lacks the functionality you and I describe.
I find it easy and intuitive to use. Being able to define the column / row content is a big plus. I can arrange any DBtable and display a subset in any fashion I choose.

COBRASoft has posted a fine example of modules, doing the same grid (only WAY more), that may help you out.
 

COBRASoft

Active Member
Licensed User
Longtime User
@Harris: that's why I posted the module for the grid, so people can learn and benefit from it. E.g. the color rules are quite handy, but I think most people haven't even looked at it and certainly not at the code :).
 

Harris

Expert
Licensed User
Longtime User
Thanks.

I will check it out.
 

kuntasev

Member
Licensed User
Longtime User
When we update, delete and insert values ​​in the table?
Insert , delete and update a table row
 

Harris

Expert
Licensed User
Longtime User
Don't quite understand the question above (first line).
Is it in reference to: "Refresh is coming soon." - as is your second line?

Thanks
 

Harris

Expert
Licensed User
Longtime User
Stefano,

Have you had the opportunity to look at COBRA's examples?

As he stated: "that's why I posted the module for the grid, so people can learn and benefit from it. "

He certainly has a grasp of what grids (and a heck of alot more) are about - much more than my humble expectations could dream of.

My needs are simple (currently) in lib format (everyone else chime in here):

1. Define columns (and headers titles) of the grid.
2. Display the grid at the location specified (fit all screen sizes - which is nearly impossible - for me anyway).
3. Select a row for edit (row_click or longclick). This is the responsibilty of my code to launch an edit form (panel, msgbox or activity) with whatever design I choose to present.
4. Refresh the grid upon return from edit. This gives the user the feeling that the edit request has been acknowledged. I have extreme trouble with this myself. Updating a listview to return to the same spot where I was seems nearly impossible - unless someone has found the solution.
5. Update the source table with rows that have been modified. Easy to do... when your mem table has the updated values.

DBGrid from Borland (Delphi, CB6) has spoiled many of us. We think everything should be so easy. As we can see here in what is trying to be accomplished - it is not.

I, as many others, thank you for your efforts and feel your pain thru the learning curve. We also thank the others mentioned above for their contribution (sometimes at risk to themselves) for revealing what they have discovered and developed at work at at play.

I think we need a reward system (money talks - bullshit walks).

See my next post under bugs & wishlists.
 

stefanobusetto

Active Member
Licensed User
Longtime User
Hi everyone,
especially to Harris who is pushing me in improving the grid.
Tanks a lot!
Just to begin with, the grid has been developed to allow only the selection from a set of rows of a table.
As soon as i have finished it i have realized that i could have extended it to allow better user experience (colors, scrolling, ...) but also to simplify some programming tasks.
I mean adding, deleting and updating data.
I'm working now to allow changes of the xnTable to be reflected in the xnGrid.
Unfortunately i have to rewrite some code but this is not a big deal.
I think i'll be able to post the changes in a week or so.
COBRA's grid is great and it is an excellent example of what you can achieve.
But i'm not going to add editing capabilities to the xgGrid (at least for now).
I prefer to keep the xnGrid as lite as possible.
But mainly i plan to edit the data of the grid in a separate activity, msgbox, ...
By the way i really like b4a very much! :D But i prefer to create java libraries to perform common tasks. They are better extendable. Even if far more complex to develop.
So to answer Harris ( points 4 and 5 ) and kuntasev : editing will be soon available.
 

stefanobusetto

Active Member
Licensed User
Longtime User
@harris
what do you mean with
"2. Display the grid at the location specified (fit all screen sizes - which is nearly impossible - for me anyway)."
 
Top