B4J Tutorial Customized ListView

rwblinn

Well-Known Member
Licensed User
Longtime User
Hi,

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

B4X:
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
B4X:
Dim ap As AnchorPane
ap.Initialize("")
Dim lbl1 As Label
lbl1.Initialize("")
lbl1.Text = "Hello World"                  
lbl1.Font = fx.DefaultFont(16)
ap.AddNode(lbl1, 0, 0, lv.Width, 20dip)
lv.Items.Add(ap)
 

StarinschiAndrei

Active Member
Licensed User
Longtime User
With this it work fine.
Thank you
 

TomDuncan

Active Member
Licensed User
Longtime 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
 

rwblinn

Well-Known Member
Licensed User
Longtime User
Hi Tom,

one way can think of is:

Set the Selection Mode of the Listview to MULTIPLE
B4X:
'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
B4X:
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
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…