B4J Tutorial Customized ListView

Discussion in 'B4J Tutorials' started by Erel, Nov 25, 2013.

  1. rwblinn

    rwblinn Well-Known Member Licensed User

    Hi,

    the item added to the listview is an anchorpane which contains a label. To get the text of the label, use

    Code:
    Dim ap As AnchorPane = lv.SelectedItem
    Dim lbl1 As Label = ap.GetNode(0)
    Log(lbl1.Text)
    This is an example of how to add an anchorpane with a label
    Code:
    Dim ap As AnchorPane
    ap.Initialize(
    "")
    Dim lbl1 As Label
    lbl1.Initialize(
    "")
    lbl1.Text = 
    "Hello World"                  
    lbl1.Font = fx.DefaultFont(
    16)
    ap.AddNode(lbl1, 
    00, lv.Width, 20dip)
    lv.Items.Add(ap)
     
  2. StarinschiAndrei

    StarinschiAndrei Active Member Licensed User

    With this it work fine.
    Thank you
     
  3. TomDuncan

    TomDuncan Active Member Licensed User

    With the images example can I select more than 1 image, Then after get all images selected.
    Nice to have a highlight for selected.
    1 click to select then click on it again to unselect. (well a thought)

    Tom
     
  4. rwblinn

    rwblinn Well-Known Member Licensed User

    Hi Tom,

    one way can think of is:

    Set the Selection Mode of the Listview to MULTIPLE
    Code:
    'Set the selection mode of the listview
    'Parameter: Listview, Selectionmode with value SINGLE or MULTIPLE - Exact case to be used
    'Example: ListviewSetSelectionMode(ListView1, "MULTIPLE")
    Sub ListviewSetSelectionMode(lvw As ListView, selectionmode As String)
        
    Dim joListView As JavaObject = lvw
        
    Dim joSelectionMode As JavaObject
        joSelectionMode.InitializeStatic(
    "javafx.scene.control.SelectionMode")
        joListView.RunMethodJO(
    "getSelectionModel"Null).RunMethod("setSelectionMode"Array(joSelectionMode.RunMethod("valueOf"Array(selectionmode))))
    End Sub
    Select the Listview Indices
    Code:
    Dim l As List = ListView1.GetSelectedIndices
    Log("Items Total: " & ListView1.Items.Size & ", Selected: " & l.size)
    For i = 0 To l.Size - 1
      
    Log("Selected Index: " & l.Get(i))
    Next
     
    TomDuncan likes this.
  5. TomDuncan

    TomDuncan Active Member Licensed User

    Thanks so much Rob, works like a charm.
    Tom
     
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