Oct 29, 2014 Replies: 3 I needed to keep two ListViews scrolling in sync, so searching the internet I found this: http://stackoverflow.com/questions/16937470/listen-to-scrollbar-change-in-listview which I have ported to B4j, and added a few extra tweaks. There is a bit of JavaObject jiggery pokery like using a Java Iterator, and setting up a value change listener. It also syncs the selection of the items between the two lists. The example syncs the Vertical scroll bar, it is also possible to sync the Horizontal scroll bar or both. I thought I'd share as it may be useful to someone. Requires JavaObject. Attachments LVSyncClass.zip LVSyncClass.zip 2.8 KB · Views: 901 LVSync-2.zip LVSync-2.zip 3.1 KB · Views: 845 Last edited: Oct 30, 2014 Click to expand...
I needed to keep two ListViews scrolling in sync, so searching the internet I found this: http://stackoverflow.com/questions/16937470/listen-to-scrollbar-change-in-listview which I have ported to B4j, and added a few extra tweaks. There is a bit of JavaObject jiggery pokery like using a Java Iterator, and setting up a value change listener. It also syncs the selection of the items between the two lists. The example syncs the Vertical scroll bar, it is also possible to sync the Horizontal scroll bar or both. I thought I'd share as it may be useful to someone. Requires JavaObject.
stevel05 Expert Licensed User Longtime User Oct 30, 2014 #2 I've created this functionality as a class (added to the first post), you now just need to Create a ListViewControl Object: Code: Private LVC As ListViewControl Initialize it with an array of listview objects and the orientation you want to control: Code: 'Add the listviews to be synced to the list, the first added is assumed to be the master and will display the scroll bar LVC.Initialize(Array As ListView(ListView2,ListView3,ListView1),"VERTICAL") And add two Subroutines for each ListView added to the control in the module that creates the ListViewControl Object: Code: Sub ListView1_SelectedIndexChanged(Index As Int) LVC.SelectedIndexChanged(Index,Sender) 'Add additional code below here End Sub Sub ListView1_MousePressed (EventData As MouseEvent) LVC.MousePressed(Sender) 'Add additional code below here End Sub The Calls to the ListViewControl in the first line of the subs are required for it to function. The code has been improved to handle the scrollwheel , scrolling on any of the lists will move them all.
I've created this functionality as a class (added to the first post), you now just need to Create a ListViewControl Object: Code: Private LVC As ListViewControl Initialize it with an array of listview objects and the orientation you want to control: Code: 'Add the listviews to be synced to the list, the first added is assumed to be the master and will display the scroll bar LVC.Initialize(Array As ListView(ListView2,ListView3,ListView1),"VERTICAL") And add two Subroutines for each ListView added to the control in the module that creates the ListViewControl Object: Code: Sub ListView1_SelectedIndexChanged(Index As Int) LVC.SelectedIndexChanged(Index,Sender) 'Add additional code below here End Sub Sub ListView1_MousePressed (EventData As MouseEvent) LVC.MousePressed(Sender) 'Add additional code below here End Sub The Calls to the ListViewControl in the first line of the subs are required for it to function. The code has been improved to handle the scrollwheel , scrolling on any of the lists will move them all.
Alberto Michelis Well-Known Member Licensed User Longtime User Jul 31, 2015 #3 Can this be ported to a B4A project?
stevel05 Expert Licensed User Longtime User Aug 1, 2015 #4 Unfortunately not, it would have to be written specifically for B4a.