Programing Center Member Jun 13, 2020 #1 Hi, i have a List and i want to Randomize my List For example my List content is : B4X: Copy Dim listview As ListView Dim list As List list.Initialize list.Add("Banana") list.Add("home") list.Add("car") list.Add("cat") list.Add("B4a") For i = 0 To list.Size -1 listview.AddSingleLine(list.Get(i)) Next I want to randomly move items from my list Is there any code? Last edited: Jun 13, 2020
Hi, i have a List and i want to Randomize my List For example my List content is : B4X: Copy Dim listview As ListView Dim list As List list.Initialize list.Add("Banana") list.Add("home") list.Add("car") list.Add("cat") list.Add("B4a") For i = 0 To list.Size -1 listview.AddSingleLine(list.Get(i)) Next I want to randomly move items from my list Is there any code?
B Brian Dean Well-Known Member Licensed User Longtime User Jun 13, 2020 #2 I want to randomly move items from my list Click to expand... If you mean that you want to select items from the list in random order then use something like this ... B4X: Copy Private Sub getRandomItem(input As List) As String If (input.Size < 1) Then Return "" Dim i As Int = Rnd(0, input.Size) Dim selection As String = input.Get(i) input.RemoveAt(i) Return selection End Sub The list will be progressively destroyed, so use a copy of your real list. Upvote 0
I want to randomly move items from my list Click to expand... If you mean that you want to select items from the list in random order then use something like this ... B4X: Copy Private Sub getRandomItem(input As List) As String If (input.Size < 1) Then Return "" Dim i As Int = Rnd(0, input.Size) Dim selection As String = input.Get(i) input.RemoveAt(i) Return selection End Sub The list will be progressively destroyed, so use a copy of your real list.
Erel B4X founder Staff member Licensed User Longtime User Jun 14, 2020 #3 Do you want to shuffle the list: https://www.b4x.com/android/forum/threads/randomly-shuffle-a-string-array.39435/#content ? Upvote 0
Do you want to shuffle the list: https://www.b4x.com/android/forum/threads/randomly-shuffle-a-string-array.39435/#content ?
Programing Center Member Jun 14, 2020 #4 Erel said: Do you want to shuffle the list: https://www.b4x.com/android/forum/threads/randomly-shuffle-a-string-array.39435/#content ? Click to expand... Exactly! Code is for Array but i want to Randomize my list Upvote 0
Erel said: Do you want to shuffle the list: https://www.b4x.com/android/forum/threads/randomly-shuffle-a-string-array.39435/#content ? Click to expand... Exactly! Code is for Array but i want to Randomize my list
Erel B4X founder Staff member Licensed User Longtime User Jun 14, 2020 #5 Learn the code. Should be trivial to make it work with a list. Tip: never use ListView. Only xCLV. Upvote 0