Android Tutorial Grid Sample

Hey all,

This grid is like an open source project. It is completely written in a seperate B4A module and allows paging, 'custom' column types, horizontal and vertical scrolling, summation and basic filtering. It uses Nine Patch Images for the backgrounds of the headers, records and footers. The developer can provide the eventnames he/she wants to get triggered in the activity.

Not everything is tested but it is easy to change or adapt to your needs.

So, if your interested in this, just try the sample and be creative in here :).

Update: I've added a lot of comments to the source code and added the possibility the catch the header click event in the activity. Did some cleanup and fixed a spacing error.

Update2: Added basic ability for number formatting. To use it, you have to set the property 'NumberIntegersMin' higher than 0 by the column. 'NumberFractions' is for decimal places and 'NumberGrouping' is for grouping per 3.

Update 3: Added a DB Sample, changed some minor issues with column widths and backpanels in the DB Sample (grid code module).

Update 4: Custom Color Rules added by request on the B4A chat. With simple color rules you can now change the textcolor of the fields by a value1 and value2. You can use this for numbers or strings. See the 'ProAppGridSample' for an example.

Update 5: ProAppGridAdvSample. Added Row and Field selection (needs some activity code). Also added the possibility to change the value of a field without redrawing the whole grid. I have only implemented the Label function and it's taking autoheight into account.

Update 6: Added sorting (QuickSort) functionality and custom typefaces per column.

Update 7: Added MinHeightField to the TColumn definition. This way you can specify the height of a column by the value of another column. I updated the ProAppGridAdvSample with this and I've also added the sorting by clicking on the header in this sample.

-------------------------------------------------------------
Some screenshots of what is possible with this grid:
proappgridadvsample01.jpg
proappdbexplorer01.jpg


proappdbexplorer02.jpg


proappdbexplorer04.jpg


Greetings,
Sigurd
 

Attachments

  • ProAppGridDBSample.zip
    51.7 KB · Views: 1,649
  • ProAppGridSample.zip
    35.5 KB · Views: 1,405
  • ProAppGridAdvSample.zip
    37.9 KB · Views: 1,291
Last edited:

duneplodder

Active Member
Licensed User
Longtime User
Very interesting. I'm looking forward to looking through this.

Would it be possible to add a few more comments in the code when you have time. e.g. a brief description at the beginning of each sub routine describing what it is doing?

Thank you very much for sharing.
 

COBRASoft

Active Member
Licensed User
Longtime User
Update

New version... Added comments, a lot of them :)

See first post for more info.
 

Mahares

Expert
Licensed User
Longtime User
Nice work SD (Cobrasoft). Can the GRID be applied to displaying a SQLite table data with multiple columns in a spreadsheet format with the heading of the table staying stationary on top. If so, can you give a hint or sample or two on how it can be accomplished. Just a small remark. On the delete icon, you may want to add a cancel option besides the 'ok'.
Merci d' avance.
 

COBRASoft

Active Member
Licensed User
Longtime User
Mahares: sure, normally the headers will stay on top. When you scroll horizontally, the column headers will scroll too, like in Excel. If you could give me a sqlite db, I could make an example with it. For now, I want to keep this first sample as simple as possible concerning libraries.

About the delete, I just show the messagebox with the ID. The delete itself has to be implemented by the developer as is the question.

P.S.: I'll try to add another nice feature... Number formatting (decimal spaces)...
 

Mahares

Expert
Licensed User
Longtime User
Cobrasoft: Per your request, here is a small database sample with only one table and several fields. I zipped it so it gets through, but relatively small in size. It does not have any proprietary data. If you can come up with something legible that can be applied to all sorts of table sizes, that would be a tremendous boost.
Salutations.
 

Attachments

  • Mydb.zip
    16.8 KB · Views: 512

COBRASoft

Active Member
Licensed User
Longtime User
Basic Number formatting

Hey all,

I've added basic number formatting for floats and doubles. See the first post for the new sample.

P.S.: Mahares, I'll see what I can do for you.

Greetings,
Sigurd
 
Last edited:

Mahares

Expert
Licensed User
Longtime User
Did you by any chance delete your attachment for your first post. There is nothing to download.

Sorry. It is there now.
 

mc73

Well-Known Member
Licensed User
Longtime User
Excellent work! I've just have one question: can we scroll vertically and horizontally at the same grid?
 

COBRASoft

Active Member
Licensed User
Longtime User
Grid DB Sample

Yes, scrolling in both directions is possible. I've just updated the first post with a DB Sample. Kinda slow due to the amount of columns, but working. Everything is created on the fly.

P.S.: Does somebody know how to get the dbtype of the columns in a table? This would make the DB Sample a lot better. Right alignment for numbers, fractions for floats, ...
 
Last edited:

Mahares

Expert
Licensed User
Longtime User
Excellent work CobraSoft. I even replaced your database with another one with a totally different structure and number of fields and it worked well. Just few preliminary suggestions as you are working to improve your product if that is what your plans are:
1. Add light color grid lines to separate the columns, particularly vertical ones.
2. Add the ability to expand the column width as some of the columns are not wide enough to display all their data.
3. You want the ability to know when you are at the 1st or last page(perhaps with button color change).
4. The ability to select a given table when the database has multiple tables.
 

COBRASoft

Active Member
Licensed User
Longtime User
@Mahares: these are all things you can change or add yourself quite easily. I just wanted to show the possibilities within 1 code module for a grid. I'm not making a database viewer per se, but it can be done easily with this grid. Perhaps I'll work some further on the current sample to make more things possible for viewing databases.

E.g. for the gridlines... You can change the backcolor of the vertical scrollview to white. This will make the gridlines white. The backpanel 'buttons' have to be changed to darker colors then or everything will be overblown.

The columnwidth can be changed per column (see column definition). Unfortunately, I haven't found yet how to know the fieldbtype of a column. This would allow more automatic configuration of the columns. Another way could be by clicking the header and ask the user for the width of that column. You'll have to re-add the whole grid after changing the width property of the specific column.
 
Last edited:

Mahares

Expert
Licensed User
Longtime User
CobraSoft asks:
P.S.: Does somebody know how to get the dbtype of the columns in a table? This would make the DB Sample a lot better. Right alignment for numbers, fractions for floats


The below code snippet may help you extract the field names and data type of all tables in a given database:

B4X:
Dim objCursor As Cursor
   Dim txt As String
   Dim i As Int
   txt="SELECT * FROM sqlite_master WHERE type = 'table' and name not like 'android%' " 
   objCursor = objDB.ExecQuery(txt)
   objCursor.Position=0
   For i = 0 To objCursor.RowCount - 1
                'Below displays table name and list of column names and data type
      Msgbox(objCursor.GetString("name") & CRLF & objCursor.GetString("sql"),"")
    Next
Good luck
Mahares
 

COBRASoft

Active Member
Licensed User
Longtime User
Color Rules

After a long nice chat, the idea came to add color rules for columns. See first post for more info and a sample.

@Mahares: I've got so far already :). I'll try to implement this further, but other work is higher priority for the moment. I'll come back to this later for sure.
 

Smee

Well-Known Member
Licensed User
Longtime User
Thanks for your work and sharing Cobrasoft. i have not used this grid yet. but i will be doing down the track. a lot of programmers reguarly need to use a grid of some sort or another.

Thanks again

Joe
 

junaidahmed

Well-Known Member
Licensed User
Longtime User
Grid Error

Yes,I am appreciate to all who are using the grid.but when i run the application for grid it shows an error message as "No field recorddisabled in the class Kharind.Mis.r$Drawable" where Kharind.Mis is my Package Name.Pls see the attached file and advise how to solve this issue.
 

Attachments

  • Error.jpg
    Error.jpg
    53.5 KB · Views: 416

junaidahmed

Well-Known Member
Licensed User
Longtime User
Sorry for disturb,I have solved my above problem that i have faced.Actually Grid is fine when compare to Tableview using scrollview but there are some feature are not available in grid like

1.SelBlock row ----> Selected row should be highlated
2.Cell Color ------> Set color for Particular cell
3.ColSpan----------> Group Column Should be Span
4.ColFreeze------> Particular Column Should be Freeze horizontally.

If the above feature will updated,this grid will be useful to all Basic4Android Developer.

Sorry for my bad English
 

COBRASoft

Active Member
Licensed User
Longtime User
@junaidahmed: I agree it's not a fully functional grid, certainly not with grouping and the spanning.

Selection and fixed columns are possible, but aren't implemented yet. You're free to extend this module to your wishes :).
 
Top