B4J Code Snippet Tableview header wrap text

Discussion in 'B4J Code Snippets' started by stevel05, Jan 20, 2016.

  1. stevel05

    stevel05 Expert Licensed User

    SubName: SetTableHeaderWrap

    Allows the table view header text to wrap.


    Code:
    Sub SetTableHeaderWrap(Table As JavaObject, PrefHeight As Int)

        
    Dim HeaderRow As Pane = Table.RunMethod("lookup",Array("TableHeaderRow"))
        
    For Each N As JavaObject In HeaderRow.GetAllViewsRecursive
            
    If N Is Label Then
                
    Dim NL As Label = N
                
    If PrefHeight <> -1 Then NL.PrefHeight = PrefHeight
                
    'Seems to lose the text centering
                CSSUtils.SetStyleProperty(NL,"-fx-text-alignment","center")
                N.RunMethod(
    "setWrapText",Array(True))
            
    End If
        
    Next
    End Sub
    Set the PrefHeight to -1 to leave it unchanged.

    Dependencies: JavaObject, CSSUtils

    CSSUtils is available here: https://www.b4x.com/android/forum/threads/class-cssutils.61824/

    Tags: B4j TableView Header Wrap Text Get Header Row
     
    Last edited: Jan 20, 2016
    Kope, DonManfred, Erel and 2 others like this.
  2. Erel

    Erel Administrator Staff Member Licensed User

    Nice. I recommend using CSSUtils.SetProperty instead of appending the attribute to the style. The advantage of CSSUtils.SetProperty is that it will replace the existing attribute (if such exists).
     
    stevel05 likes this.
  3. stevel05

    stevel05 Expert Licensed User

    Yes, I forgot about that one. I Should get used to using it. Will change it. Thanks
     
    Last edited: Jan 20, 2016
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