B4J Question ListSelectionView add event when an item on list (source or target) is clicked/selected

Mahimahi

Member
Licensed User
Can anyone shed some light in adding an event to ListSelectionView so when an item on list (source or target) is clicked/selected, an event will be raised? I understand from reading, ListSelectionView does not raise any event by default. I wanted to know which item is clicked on in the e.g. source list, and copy that item's text to a textfield to do further manipulations.

ListSelectionView is a control from ControlFX Library, referencing https://www.b4x.com/android/forum/threads/controlsfx-library.50700/#content

upload_2019-2-24_13-39-6-png.77710


Please advise. Thanks.
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
Here:
B4X:
Sub AppStart (Form1 As Form, Args() As String)
   MainForm = Form1
   MainForm.RootPane.LoadLayout("1") 'Load the layout file.
   MainForm.Show
   Dim jo As JavaObject = ListSelectionView1
   Dim event As Object = jo.CreateEventFromUI("javafx.collections.ListChangeListener", "ListChange", Null)
   jo.RunMethodJO("getSourceItems", Null).RunMethod("addListener", Array(event))
End Sub

Sub ListChange_Event (MethodName As String, Args() As Object) As Object
   If MethodName = "onChanged" Then
       Dim Change As JavaObject = Args(0)
       If Change.RunMethod("next", Null) = True Then
           Dim MovedFromSourceToTarget As List = Change.RunMethod("getRemoved", Null)
           Dim MovedFromTargetToSource As List = Change.RunMethod("getAddedSubList", Null)
           For Each s As String In MovedFromSourceToTarget
               Log("Moved to target: " & s)
           Next
           For Each s As String In MovedFromTargetToSource
               Log("Moved to source: " & s)
           Next
       End If
   End If
   Return Null
End Sub
 
Upvote 0

Mahimahi

Member
Licensed User
Thank you for your example code Erel. Is it possible do similar to raise an event when an item is selected on "Source" list? Without user moving the item from "Source" list to "Target" list, or vice versa. Something like "selectedIndex". Please advise. Thanks a lot.
 
Upvote 0
Top