Android Question Newbie: What is the proper way to create a grid?

clurbina

Member
Licensed User
Longtime User
I have looked at the forum for a few days and I cannot find a simple grid example. Using labels, I made a grid with row headers and column headers. I am sure that this is not the way to do it. Can someone help? The headers should be a different color from the body and horizontal and vertical lines are needed. Thanks.
 

Attachments

  • DumbGrid.zip
    9.1 KB · Views: 284

clurbina

Member
Licensed User
Longtime User
Thanks, Jeffrey for your timely reply. I have studied that example and the other one at https://www.b4x.com/android/forum/threads/class-flexible-table.30649/ and I still do not see where the lines are drawn. I have both open because I suspect that's where the answer is, but I am still not familiar with the syntax to know how to draw the lines. I actually downloaded the zip files and ran them and they work. And how do I color column 0? Cell by cell?
 
Upvote 0

Jeffrey Cameron

Well-Known Member
Licensed User
Longtime User
Digging into the example is absolutely the best course of action, you will learn far more from investigating how others have accomplished this already.

Having said that, generally the lines are not "drawn" they are either labels themselves or inferred from the background color. For example, by inferred I mean:
B4X:
+===============+
| LABEL    A    |
+===============+
background color is visible here due
to gap between labels, giving the appearance
a colored line between them
+===============+
| LABEL    B    |
+===============+
If you want something fancier, you can place a very thin label (e.g. 3dip, with no text) between "LABEL A" and "LABEL B" with no gap at all, and then you can color the background for the label as desired.
 
Upvote 0

clurbina

Member
Licensed User
Longtime User
OK, thanks Jeffrey for your kind reply. I will continue digging into the example. And I will also try the thin label approach.
 
Upvote 0

clurbina

Member
Licensed User
Longtime User
I got it, Jeffrey. By making the rows a bit shorter and the columns a bit narrower, the background shows up. so if i made the background blue, the "lines" would be blue. I would have never got it except for your help. Thanks again.
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
What exactly do you want to do or what do you expect.
The Flexible Table is more recent, it is an evolution of the Table class.
... and I still do not see where the lines are drawn.
Each cell is a Label, they have a small space between each other generating the 'lines', which are not drawn.
You cannot set individual colors for each cell.
You can set two colors, one for odd lines and one for even lines.
There are routines included to read csv files or databases directly into the Table.

If you want to all this on your own, you may have a look at this project SQLiteDB, it is a very old project, but you could see how it is constructed.
 
Upvote 0
Top