Here is another way:I just want a snippet to make it auto adapt to screen size.
Dim w As Int = B4XTable1.mBase.Width
w = Root.Width
Dim l As List
l.Initialize
Dim k As Int
l.AddAll(Array As Double(.20, .15, .10, .40, .10, .05))
For Each col As B4XTableColumn In B4XTable1.Columns
col.Width=l.Get(k)*w
k=k+1
Next
Dim l As List
l.Initialize
Dim k As Int
l.AddAll(Array As Int(20%x, 15%x, 10%x, 40%x, 10%x, 5%x))
For Each col As B4XTableColumn In B4XTable1.Columns
col.Width=l.Get(k)
k=k+1
Next
Thanks I just want a snippet to make it auto adapt to screen size. Thanks for the links.
Dim allcolwidth As Int=editcol.Width
Dim colpadding As Int=0
Dim newwidth As Int = 0
Dim formwidth As Int = B4XPages.GetNativeParent(Me).Width - (table1.mBase.Left * 2) 'remove the distance of b4xtable1 from width
For i = 0 To B4XTable1.Columns.Size-1
Dim thiscol As B4XTableColumn = B4XTable1.Columns.get(i)
allcolwidth=allcolwidth+thiscol.width+colpadding
Next
If allcolwidth<formwidth Then 'this will need the opposite...
Dim cw As Int = ((formwidth)-(allcolwidth)) / (B4XTable1.Columns.Size.Length) 'also here opposite... then you will divide it by the size of columns
'Log(cw)
For i = 0 To B4XTable1.Columns.Size-1
Dim thiscol As B4XTableColumn = B4XTable1.Columns.get(i)
newwidth=thiscol.width+cw ' and you will use (-)
anarraywiththesizes(i)=newwidth 'you will use after the loops... to set them
Next
End If
Bonjour: Another quick and simple way:simple way to make B4XTable Fit Screen Size
Dim w As Int = B4XTable1.mBase.Width
w = Root.Width
Dim numberofcols As Int =6 'or any other number for your columns
For Each col As B4XTableColumn In B4XTable1.Columns
col.Width=w/numberofcols 'you can alternatively assign different widths to dif cols
Next
Here is another way:I just want a snippet to make it auto adapt to screen size.
Dim w As Int = B4XTable1.mBase.Width
w = Root.Width
Dim l As List
l.Initialize
Dim k As Int
l.AddAll(Array As Double(.20, .15, .10, .40, .10, .05))
For Each col As B4XTableColumn In B4XTable1.Columns
col.Width=l.Get(k)*w
k=k+1
Next
Dim l As List
l.Initialize
Dim k As Int
l.AddAll(Array As Int(20%x, 15%x, 10%x, 40%x, 10%x, 5%x))
For Each col As B4XTableColumn In B4XTable1.Columns
col.Width=l.Get(k)
k=k+1
Next
(ArrayIndexOutOfBoundsException) java.lang.ArrayIndexOutOfBoundsException: Index 0 out of bounds for length 0
Public Sub MakeTableFitScreenSize(B4XTable1 As B4XTable,B4XTableEditCol As B4XTableColumn)
Dim anarraywiththesizes() As Int
Dim allcolwidth As Int = B4XTableEditCol.Width
Dim colpadding As Int=0
Dim newwidth As Int = 0
Dim formwidth As Int = B4XPages.GetNativeParent(Me).Width - (B4XTable1.mBase.Left * 2) 'remove the distance of b4xtable1 from width
For i = 0 To B4XTable1.Columns.Size-1
Dim thiscol As B4XTableColumn = B4XTable1.Columns.get(i)
allcolwidth=allcolwidth+thiscol.width+colpadding
Next
If allcolwidth<formwidth Then 'this will need the opposite...
Dim cw As Int = ((formwidth)-(allcolwidth)) / (B4XTable1.Columns.Size) 'also here opposite... then you will divide it by the size of columns
Log(cw)
For i = 0 To B4XTable1.Columns.Size-1
Dim thiscol As B4XTableColumn = B4XTable1.Columns.get(i)
newwidth=thiscol.width+cw ' and you will use (-)
anarraywiththesizes(i)=newwidth 'you will use after the loops... to set them
Next
End If
End Sub
I hope this helps if I am understanding your code and post. But if you set the number of columns in this below line, in your subcould you help me make this code work properly ?