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

Discussion in 'Android Questions' started by fernando gibert, May 12, 2019.

Thread Status:
Not open for further replies.
  1. fernando gibert

    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 !!
     
  2. Mahares

    Mahares Well Known Member Licensed User

    Try something like this:
    Code:
    '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: May 12, 2019
  3. jimmyF

    jimmyF Active 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"
     
  4. mangojack

    mangojack Well-Known 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.
     
    jimmyF likes this.
  5. fernando gibert

    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


    [​IMG]

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

    Erel Administrator Staff Member Licensed User

    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:
    Code:
    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.
     
    jimmyF and mangojack like this.
  7. fernando gibert

    fernando gibert Member Licensed User

    Sorry , my sample was disallocated due to blanks...

    19 Tim Goyer
    1 Luis Gonçalves
     
  8. fernando gibert

    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 !!!
     
  9. Erel

    Erel Administrator Staff Member Licensed User

    You haven't understood my post. Reread it.

    It should be possible. I still don't understand the problem.

    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
     
  10. fernando gibert

    fernando gibert Member Licensed User

    In Erel's example:

    customer id column in row 1 id.e. 19
    is not aligned in row 2 id.e. _1

    so figure 1 should be under figure 9
     
  11. fernando gibert

    fernando gibert Member Licensed User

  12. fernando gibert

    fernando gibert Member Licensed User

    This is the way i found to have aligned numbers !!!
     
  13. Mahares

    Mahares Well Known Member Licensed User

    Why don't you use the code I posted in Post#2. I have tested it on one of my project and it works. You do not need to pad the numbers with *, instead of arguing with everybody.
     
    DonManfred likes this.
  14. Erel

    Erel Administrator Staff Member Licensed User

    The correct solution is to combine your code with option 1 from post #6.
     
  15. jimmyF

    jimmyF Active Member Licensed User

    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.
     
    mangojack likes this.
  16. fernando gibert

    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..
     
  17. Erel

    Erel Administrator Staff Member Licensed User

    It should be simple to align the cells however you like. Apparently we aren't able to help you so I'm closing this thread.
     
    Mahares likes this.
Thread Status:
Not open for further replies.
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice