Android Question b4x table view number right alignment and text left alignment

Status
Not open for further replies.

fernando gibert

Member
Licensed User
When using b4xtableview I found no way to make columns be aligned left ( text ) or number (right)

columns are always centered weight. Tried to copy fileds to listview right/left gravity an then to row (xx)

but no change is done.

Thanks !!
 

Mahares

Well Known Member
Licensed User
I found no way to make columns be aligned left ( text ) or number (right)
Try something like this:
B4X:
'AVMCFD is the name of the column
'        SetColumnAlignment("AVMCFD", "BOTTOM", "RIGHT")  'vert, hor
'        SetColumnAlignment("AVMCFD", "TOP", "RIGHT")  'vert, hor
'        SetColumnAlignment("AVMCFD", "CENTER", "LEFT")  'vert, hor
        SetColumnAlignment("AVMCFD", "CENTER", "RIGHT")  'vert, hor  AVMCFD is the name of the column

Sub SetColumnAlignment(columnID As String, alignmentV As String, alignmentH As String)
    Dim column As B4XTableColumn = B4XTable1.GetColumn(columnID)
    For i = 1 To column.CellsLayouts.Size - 1        'starts at 1 due to header
        Dim pnl As B4XView = column.CellsLayouts.Get(i)
        pnl.GetView(0).SetTextAlignment(alignmentV, alignmentH)
    Next
End Sub
 
Last edited:

jimmyF

Active Member
Licensed User
Try something like this:
Great code, thank you for this.

And I found I can make it work consistently when the call is made from the sub, "B4XTable1_DataUpdated"
 

mangojack

Well-Known Member
Licensed User
Great code, thank you for this.

And I found I can make it work consistently when the call is made from the sub, "B4XTable1_DataUpdated"
I dont think you have to repeatedly set the Alignment.. Only once when you have set your columns should do the trick.
 

fernando gibert

Member
Licensed User
I've tried setcolumnalignment but results remain not fully aligned.



my wish is to have columns look as 19 TIM GOYER
1 luis gonçalves
23 john gordon




and it looks like erel's sample customer id i.e. number not right aligned .
and name text not left aligned.
 

Erel

Administrator
Staff member
Licensed User
I dont think you have to repeatedly set the Alignment.. Only once when you have set your columns should do the trick.
I will clarify this point. B4XTable creates the cells when needed. This means that when the table is resized more cells will be created. This is not an issue in B4A as the table is created and usually never resized (until the activity is recreated which means that the table is recreated as well).

In B4J and B4i you cannot assume that new cells will not be created. There are two ways to "solve" it.

1. Recommended method:
B4X:
B4XTable1.MaximumRowsPerPage = 20
B4XTable1.BuildLayoutsCache(B4XTable1.MaximumRowsPerPage)
This code sets the maximum number of rows and then forces the table to create cells for this number of rows. You can of course change it to whichever number you like. 20 is probably large enough.
You can safely modify the cells after this call. New cells will never be created.

2. Update the cells in DataUpdate event.

I recommend to use option #1 in B4A as well, as the cells are not immediately created by default.
 

fernando gibert

Member
Licensed User
Rows per page has nothing to interact with the columns width itself nor it shown data alignment.

Just to see data in the b4xtable as it was a grid or a simple sql query output is my desire:

fields ajusted left for text and right for numbers.

possibility to add graphs into the columns is something wonderful !!!
 

Erel

Administrator
Staff member
Licensed User
Rows per page has nothing to interact with the columns width itself nor it shown data alignment.
You haven't understood my post. Reread it.

fields ajusted left for text and right for numbers.
It should be possible. I still don't understand the problem.

possibility to add graphs into the columns is something wonderful !!!
Not related to this thread but it is also possible: https://www.b4x.com/android/forum/threads/b4x-b4xtable-with-custom-cells-layout.102352/#post-642432
 

jimmyF

Active Member
Licensed User
I dont think you have to repeatedly set the Alignment.. Only once when you have set your columns should do the trick.
You are right. I had put the call to align just after the call to set the column. I should have place it at the end of the initialization sub. There it works fine.
 

fernando gibert

Member
Licensed User
Numbers padding with * has been the sole useful option,
Padding with blanks makes the output to be centred in the column.
Iwould like to pad with blanks ,but it needs a visible character.

Before i tried to write the values into a listview centered right.
THE VALUES IN LISTVIEW LOOK WELL, but copying the value to the column it automoves center.
In resume columns with variable number of caracters in a defined column width always shown centered..
 
Status
Not open for further replies.
Top