B4A Library [Class] Flexible Table

klaus

Expert
Licensed User
Longtime User
@watersoft.
I looked at the problem trying to scale a Table with the Scale module.
Unfortunately it will not work.

The error you get is a problem with the ScrollView2D library version 1.2 you won't get it with version 1.1.
I reported it in this Tread.

But the main problem is that the internal Labels in the Table are automatically redefined when you scroll.
In the Scale module it's impossible to know that the CustomView is a Table.
So it's impossible to change the internal dimensions.
The visible Labels are scaled but not the others.
 

klaus

Expert
Licensed User
Longtime User
Some users report to me some visual errors in the Table, like the Headers and row height in some moviles.
From the screenshot it seems that the RowHeight and TextSize are not matching, either RowHeight is too small or TextSize is too big.
Do these users have set the Font size on their device to a big size ? This could be the reason.

The problem with TextAlignment was an error in the Table class.
New updated version 2.10 in the first post.
 

watesoft

Active Member
Licensed User
Longtime User


Thanks Klaus
I use the latest version ScrollView2D, The error does not occur. but the result,as you said, is not ideal to scale a Table with the Scale module.
As a transitional, In table class, I add "Scale.GetScaleY" to Public Sub DesignerCreateView,As shown below in bold font:

Public Sub DesignerCreateView (Base As Panel, Lbl As Label, Props As Map)
pnlTable = Base
cLeft = Base.Left
cTop = Base.Top
cWidth = Base.Width
cHeight = Base.Height
pnlTable.Color = Colors.Transparent
'sets the text alignment property
cAlignment = Gravity.CENTER
cHeaderAlignment = Gravity.CENTER
cLineWidth = DipToCurrent(Props.Get("LineWidth"))

cHeaderColor = Props.Get("HeaderColor")
cTableColor = Props.Get("TableColor")
cHeaderTextColor = Props.Get("HeaderTextColor")
cTextColor = Props.Get("CellTextColor")
cRowColor1 = Props.Get("Row1Color")
cRowColor2 = Props.Get("Row2Color")
cSelectedRowColor = Props.Get("SelectedRowColor")
cSelectedCellColor = Props.Get("SelectedCellColor")

cTextSize = Props.Get("TextSize")*Scale.GetScaleY

cRowHeight = DipToCurrent(Props.Get("RowHeight"))*Scale.GetScaleY
cHeaderHeight = DipToCurrent(Props.Get("HeaderHeight"))*Scale.GetScaleY
cShowStatusLine = Props.Get("ShowStatusLine")
InitTable
End Sub

Add horizontal and veritcal Anchor on Table View ,Then I ScaleAllX the views except Table view. It looks pretty good in simulators with Different resolutions and sizes.
But I still want to scale a Table with the Scale module if it is possible.Sincerely hope you can add this feature to scale module next update.

Best ragards
 

klaus

Expert
Licensed User
Longtime User
But I still want to scale a Table with the Scale module if it is possible.
Unfortunately this is not possible.
A CustomView is considered as a Panel with the GetType function.
For 'standard' CustomViews the Scale module works because the CustomView.Panel will be scaled with all its childs.
I tryed to use the Tag property to know if the Panel is a Table class, but this doesn't work because in this case I don't know the Table instance.
But the Table is special because the Labels are generated dynamically which needs a special treatment.

Attached you find a modified version of the table class.
I added a ScaleTable(ScaleX As Double, ScaleY As Double, ScaleAllDone As Boolean) routine.
Where you provide the two scale factors.
You can use Scale.ScaleAll to scale everything and the use:
Table2.ScaleTable(Scale.GetScaleX, Scale.GetScaleY, True)
to scale only the internal Labels.
 

Attachments

  • TestTableScaleV2_11.zip
    31.4 KB · Views: 219

vbmundo

Well-Known Member
Licensed User
Hi Klauss,

Your Lib have a SORT BUG...

In Numeric column, the sort put first the value "10049" to "9954"

I'm running with diferent data and it's allways the same...

You evaluate an expresion from left to right, but numbers need to evaluate from right to left, because "10500" is greater than "9566" but you compare "1" to "9" and revert the order.
 

LucaMs

Expert
Licensed User
Longtime User

I tried the project as it is, Klaus:

Copying updated assets files (4)
** Service (starter) Create **
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
260
260
Error occurred on line: 278 (Scale)
java.lang.NullPointerException
at b4a.example.scale._scaleall(scale.java:80)
at b4a.example.scale._scaleview(scale.java:643)
at b4a.example.scale._scaleall(scale.java:99)
at b4a.example.scale._scaleview(scale.java:548)
at b4a.example.scale._scaleall(scale.java:83)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:703)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:337)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:247)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:134)
at b4a.example.main.afterFirstLayout(main.java:102)
at b4a.example.main.access$000(main.java:17)
at b4a.example.main$WaitForLayout.run(main.java:80)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:149)
at android.app.ActivityThread.main(ActivityThread.java:5061)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:794)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:610)
at dalvik.system.NativeStart.main(Native Method)
** Activity (main) Resume **
 

vbmundo

Well-Known Member
Licensed User
The values are strings. Sorting a string will do it this way. Add the value as 09566 and it will be Sorten correctly i guess

Can't the Script detect that the Column have numeric values and sort right ?

Because if you need to fill with "1" value, you can't show "000001"

Imagine a Double Value... 45.40, you can't show 00000045.40
 
Last edited:

watesoft

Active Member
Licensed User
Longtime User

Thanks Klaus to give me a satisfactory answer, I use the modified version of the table class, It's very good in my project.
One thing to note, the modified version can't add table to panel, Otherwise, Error occurred:java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.Object anywheresoftware.b4a.objects.PanelWrapper.getObject()' . It may be confusing to some people, but this does not affect me, I may add table to Activity.

best regards
 

klaus

Expert
Licensed User
Longtime User
Can't the Script detect that the Column have numeric values and sort right ?
Yes, this could be done, but it would be very time consuming to check if all the data in a column are numbers.
It would be more efficient to add an array with the data types for the columns and then sort the table according to the data type of the selected column.
There exist a routine in the Table class to sort numbers sortTableNum.
I will have a look at this during the next days.
 

klaus

Expert
Licensed User
Longtime User
Otherwise, Error occurred:java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.Object anywheresoftware.b4a.objects.PanelWrapper.getObject()'
Do you have an example, I tested the program by adding the table onto a Panel in the Designer and in the code, both work as expected.
 

klaus

Expert
Licensed User
Longtime User
@vbmundo
Can you try the attached version of the Table class.
I added an array for the column data types and two methods to change them.
In the test project the upper table sorts the number column with strings and the lower table with numbers.
 

Attachments

  • TableV2_12.zip
    27.9 KB · Views: 235

vbmundo

Well-Known Member
Licensed User
@vbmundo
Can you try the attached version of the Table class.
I added an array for the column data types and two methods to change them.
In the test project the upper table sorts the number column with strings and the lower table with numbers.

Thanks Klauss

I will try...

I have some problems with the ROW HEIGHT , I put 35 at first, but in Tablets or 5' SmartPhones , 35 pixels is too short. then I put 35dip, but now the Row is too tall.

No other users have the same font size, then... can you read the user font size, the movil dimensions, and recalculate the Row height ?

I can try to form the algorithm but I have enough experience in B4A and handling all this.

In 35dip the Head rows dissapear.

Regards
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…