B4A Library [Class] Flexible Table

Sergio Castellari

Active Member
Licensed User
I never loaded data from MySQL to B4x but I think that there should also be a MySql-builtin-function to format an internal datetime value into a string.
Hi @Kanne,

Of course it does.
But when using jRDC2 to get the query, jRDC2 returns the DATE fields as TICKS. So this routine simply formats the date as we wish.

Cheers
 

artsoft

Member
Licensed User
Hey Klaus!
Hey Kanne!

Sorry for the late response.... I was very busy the last days.
All my problems are fixed now - thanks for all your tips and the new versions of Table.bas. :)

________________________________________

The current issue I have is the choice of the correct text size - based on the given smart device or tablet.

Using this structure:

B4X:
    Dim lv As LayoutValues
    lv = GetDeviceLayoutValues
I have the width, the height and the scale of the device's resolution.

________________________________________

My row height (the header height as well) are based on the given %y:

B4X:
    Table1.RowHeight = Ceil(4%y)
    Table1.HeaderHeight = Table1.RowHeight
This works great and looks perfect on each test device.


This works also on each device:

B4X:
Table1.RowHeight = Ceil(Table1.Height / 10)
So I can see always 10 rows on each device :)


_____________________________

BUT...

The question is now on how to calculate the correct Text size:

B4X:
    Dim ts As Int
    ts = Table1.RowHeight * 0.4
    Table1.TextSize = ts
My problem:
This works ok on one device and after switching to another device (in example to tablet) I see that this calculation is really wrong!



Therefore my question:
Is there a better method which can be used to calculate the correct text size - together with scale value or something like this??

Your answer is highly appreciated.

Best regards
ARTsoft

P.S.: The cell alignment is set to left and vertical center (with Bit.OR method).
 
Last edited:

Kanne

Member
Licensed User
you may search the forum by something like "calculation textsize".
I found Calculate textsize depending on label height and tested it with setting rowheight to 1/5 of table:
B4X:
    tableDes.RowHeight = Floor((tableDes.Height / 5))
    tableDes.TextSize =  Floor(tableDes.RowHeight * 500 / 1000dip)
In this case the font will fill about 50% of the cellheight which looks ok in my example - but you may test with other values.

@klaus:
setting the textsize after filling does not change the textsize for the fixed columns
 

artsoft

Member
Licensed User
you may search the forum by something like "calculation textsize".
I found Calculate textsize depending on label height and tested it with setting rowheight to 1/5 of table:
B4X:
    tableDes.RowHeight = Floor((tableDes.Height / 5))
    tableDes.TextSize =  Floor(tableDes.RowHeight * 500 / 1000dip)
In this case the font will fill about 50% of the cellheight which looks ok in my example - but you may test with other values.

@klaus:
setting the textsize after filling does not change the textsize for the fixed columns
Thanks Kanne for the tip!

Yes I also found out that the property textsize can only set before loading the data - after loading there is no chance to "resize" the text in order to adapt it to the given device resolution. This might be a really good feature.

Best regards
ARTsoft
 

Kanne

Member
Licensed User
Hi,

within my project it was possible in conjunction with .RefreshTable (only the bug with fixed columns).

I got an error when setting RowHeight before filling, but you can set Textsize before and Rowheight after - you know all values:
B4X:
tableDes.TextSize =  Floor(Floor((tableDes.Height / 5)) * 500 / 1000dip)
... (filling table)
tableDes.RowHeight = Floor((tableDes.Height / 5))
 
Last edited:

Kanne

Member
Licensed User
Hi @Kanne,

Of course it does.
But when using jRDC2 to get the query, jRDC2 returns the DATE fields as TICKS. So this routine simply formats the date as we wish.

Cheers
I can't imagine that jRDC2 will return ticks if you use
DATE_FORMAT(docdate, '%d/%m/%Y') AS Date_DMY
wihtin the SQL-statement.
The datefield will be formated as string and the middleware will give you a string.
Could you please test it for me, because I don't have a mySQL-DB und webservice to do that ... it only reflects my knowlegde of SQL.
 

artsoft

Member
Licensed User
you may search the forum by something like "calculation textsize".
I found Calculate textsize depending on label height and tested it with setting rowheight to 1/5 of table:
B4X:
    tableDes.RowHeight = Floor((tableDes.Height / 5))
    tableDes.TextSize =  Floor(tableDes.RowHeight * 500 / 1000dip)
In this case the font will fill about 50% of the cellheight which looks ok in my example - but you may test with other values.

@klaus:
setting the textsize after filling does not change the textsize for the fixed columns
@Kanne: Hi, I see that the factor (or better: the divisor) with value 5 is ok when I test the table on a smartphone. But on a tablet, this factory is too small. 5 entries on a smartphone provides a good text size - but on a test tablet .... OMG .... the table has a big height (the table covers about 80% of the screen and therefore I have a big height) and divided by 5 ... the row height is too high indeed.

I guess that we have to calculate this divisor as well ... while using the scale value of a screen.

Regards
ARTsoft
 

Kanne

Member
Licensed User
sure ... 5 rows is what you posted and asking how to fit the textsize according to the new rowheight.
You may calculate and set rowheight and the corresponding textsize as you want, e.g. to a readable size for you on the specific device.
 

Sergio Castellari

Active Member
Licensed User
I can't imagine that jRDC2 will return ticks if you use wihtin the SQL-statement.
The datefield will be formated as string and the middleware will give you a string.
Could you please test it for me, because I don't have a mySQL-DB und webservice to do that ... it only reflects my knowlegde of SQL.
Hi @Kanne !!

What you show is correct. In that case, deliver the date in a string.
My APP is sharing information with an ERP system in real time. This is why I don't want to modify queries (if not necessary) to maintain a certain order.
Also, I don't have that much knowledge. But I love B4A as it is helping me to get my APP.
Cheers!
 

Kanne

Member
Licensed User
Hi Klaus,
I tested a little with adjustment of the textheight / rowheight and found some minor bugs:
- "ScaleTable" seems not to scale the headerheight; could be solved by setting HeaderHeight to RowHeight after filling
- changing RowHeight after filling does not adjust panelheight so I have a black area at the end (when reducing) or can't scroll to the end (when increasing)
 

klaus

Expert
Licensed User
I was also looking at the ScaleTable method and improved it.
The ScaleTable method must be called before filling the Table.
Can you please test the attached Table.bas file.
 

Attachments

Kanne

Member
Licensed User
I made some test with my Table-Test-project:
V1: showing default layout (upper table runtime, lower table designer)
V2: tableRun.ScaleTable(1.5,1.5,False): scale is bigger than 1.5, also I don't want to change width / height of table, only labelsize / textsize
V3: tableRun.ScaleTable(1.5,1.5,False) & reset table width & height (before filling): scale is bigger than 1.5
V4: tableRun.ScaleTable(1.5,1.5,true): new header-hight not calculated for top of the rows
V5: tableRun.ScaleTable(1.5,1.5,true) & HeaderHeight = RowHeight (after filling): that is what I want

I don't know what the 3rd boolean-param is used for: when do I have to set it to which value ?
 

Attachments

klaus

Expert
Licensed User
Thank you for testing !
I added the ScaleTable method a long time ago, when anchors didn't exist.
At that time I wrote the Scale module, shortly after AutoScale was added in the Designer, allowing AutoScale also for views added in the code. This is mostly no more used.
The ScaleTable method was added after the Scale module to allow scaling Tables in conjunction with the Scale module, the third parameter depends if the ScaleAll method from the Scale module was used or not.
In your cases always False.

But, the ScaleTable method rescales all views in the Table!
Not sure that it will work OK with anchors.
Therfore, if you want to change only the heights and text sizes you must use the Height and TextSize properties or methods and not the ScaleTable method.
 
Top