Apr 18, 2012 Replies: 37 Deprecated ! see the updated version of Wheel as a class http://www.b4x.com/forum/basic4android-share-your-creations/18855-wheel-b4a-class.html#post108297 and the new Wheel https://www.b4x.com/android/forum/threads/a-new-wheelview.91645/post-578792 The Wheelview is a complex view, built on a scrollview with labels, and uses a timer to settle on the predefined values of the wheel. The logic was first shared by birnesoft here http://www.b4x.com/forum/bugs-wishlist/14620-spin-wheel.html#post89984 and many members of the forum contributed to the improvement till we got a really nice tool. I put the logic into a library, trying to ease the use for developers who don't have time to master the tricks there, but kept several options for personal look preferences, as well as leaving the cover on top to be done by the application. Attached also a demo program. Important note : The Tick events and the ReadWheel method are a must for the operation of the wheel. Please try it and give comments for more functionality/improvements/bugs correction. Thanks again to all the contibutors. Edit: Updated to ver 1.1 with additional two methods for updating the values without need to re-initialize, by list or by array. Also modified the name of SetValue to SetToValue to avoid misunderstandings about the functionality of the method. Edit: - example app added to ver. 1.1 Last edited: Jun 25, 2020 Click to expand...
Deprecated ! see the updated version of Wheel as a class http://www.b4x.com/forum/basic4android-share-your-creations/18855-wheel-b4a-class.html#post108297 and the new Wheel https://www.b4x.com/android/forum/threads/a-new-wheelview.91645/post-578792 The Wheelview is a complex view, built on a scrollview with labels, and uses a timer to settle on the predefined values of the wheel. The logic was first shared by birnesoft here http://www.b4x.com/forum/bugs-wishlist/14620-spin-wheel.html#post89984 and many members of the forum contributed to the improvement till we got a really nice tool. I put the logic into a library, trying to ease the use for developers who don't have time to master the tricks there, but kept several options for personal look preferences, as well as leaving the cover on top to be done by the application. Attached also a demo program. Important note : The Tick events and the ReadWheel method are a must for the operation of the wheel. Please try it and give comments for more functionality/improvements/bugs correction. Thanks again to all the contibutors. Edit: Updated to ver 1.1 with additional two methods for updating the values without need to re-initialize, by list or by array. Also modified the name of SetValue to SetToValue to avoid misunderstandings about the functionality of the method. Edit: - example app added to ver. 1.1
moster67 Expert Licensed User Longtime User Apr 18, 2012 #2 Thank you Derez, :icon_clap: just tested your demo and it works nicely.
JoanRPM Active Member Licensed User Longtime User Apr 18, 2012 #3 Derez, good job. Works like in the other thread. It also locks up a bit when you spend 31 to 1. I tried doing less than 3 panels and working (modifying the code), but not if you make more than 3 (I suppose it is done that way in the library). One thing I do not like (very personal) is that the panels are together with each other (no separation in the middle) and not gives the appearance of independent wheels. A question. How have you done, from a B4A code, a library? I would like some day, create a library, witht the code I did in the other thread (unless you do everything with Java, so for now I give up). This one has a lot of options: size, number of wheels, ... Greetings.
Derez, good job. Works like in the other thread. It also locks up a bit when you spend 31 to 1. I tried doing less than 3 panels and working (modifying the code), but not if you make more than 3 (I suppose it is done that way in the library). One thing I do not like (very personal) is that the panels are together with each other (no separation in the middle) and not gives the appearance of independent wheels. A question. How have you done, from a B4A code, a library? I would like some day, create a library, witht the code I did in the other thread (unless you do everything with Java, so for now I give up). This one has a lot of options: size, number of wheels, ... Greetings.
derez Expert Licensed User Longtime User Apr 18, 2012 #4 but not if you make more than 3 Click to expand... I have an application with 4 wheels, it works. The library does not limit the number. One thing I do not like (very personal) is that the panels are together with each other (no separation in the middle) and not gives the appearance of independent wheels. Click to expand... This is up to you - you can set the layout with spaces between the wheels (in the application,not the library), here: Code: Copy Activity.AddView(wv1,100dip, 170dip,40dip,svstep*3) Activity.AddView(wv2,140dip, 170dip,50dip,svstep*3) Activity.AddView(wv3,190dip, 170dip,70dip,svstep*3) You can change this to (didn't check how it looks): Code: Copy Activity.AddView(wv1,100dip, 170dip,40dip,svstep*3) Activity.AddView(wv2,150dip, 170dip,50dip,svstep*3) Activity.AddView(wv3,210dip, 170dip,70dip,svstep*3) How have you done, from a B4A code, a library? Click to expand... It is written in Java, and I'm just doing my first steps, following the tutorials. This one has a lot of options: size, number of wheels, ... Click to expand... The library is providing one wheel as one object, but like in the demo - you can include several such objects in an application, each with its own definitions of size, color etc. Thank you for testing and for your code. Of course, the logic in the library is the same as was developed in the thread. Edit: added the photo of separate wheels. Edit: photo of 4 wheels. Attachments scr2.png 24 KB · Views: 1,311 scr3.png 45.1 KB · Views: 1,576 Last edited: Apr 18, 2012
but not if you make more than 3 Click to expand... I have an application with 4 wheels, it works. The library does not limit the number. One thing I do not like (very personal) is that the panels are together with each other (no separation in the middle) and not gives the appearance of independent wheels. Click to expand... This is up to you - you can set the layout with spaces between the wheels (in the application,not the library), here: Code: Copy Activity.AddView(wv1,100dip, 170dip,40dip,svstep*3) Activity.AddView(wv2,140dip, 170dip,50dip,svstep*3) Activity.AddView(wv3,190dip, 170dip,70dip,svstep*3) You can change this to (didn't check how it looks): Code: Copy Activity.AddView(wv1,100dip, 170dip,40dip,svstep*3) Activity.AddView(wv2,150dip, 170dip,50dip,svstep*3) Activity.AddView(wv3,210dip, 170dip,70dip,svstep*3) How have you done, from a B4A code, a library? Click to expand... It is written in Java, and I'm just doing my first steps, following the tutorials. This one has a lot of options: size, number of wheels, ... Click to expand... The library is providing one wheel as one object, but like in the demo - you can include several such objects in an application, each with its own definitions of size, color etc. Thank you for testing and for your code. Of course, the logic in the library is the same as was developed in the thread. Edit: added the photo of separate wheels. Edit: photo of 4 wheels.
JoanRPM Active Member Licensed User Longtime User Apr 18, 2012 #5 Ok, thanks. I will try it. Regards.
JoanRPM Active Member Licensed User Longtime User Apr 18, 2012 #6 Yes it's true. It has more flexibility than I thought. I tested with 4 wheels and now it works (I was doing something wrong). It also works with negative numbers!. Good job! I've found that watching the *.xml, you can read some notes on the library that can be helpful. I still lack experience. With respect to the library, I will wait to learn a bit more. Just one more thing. Can I change the text size of the wheel? Thank you. Last edited: Apr 18, 2012
Yes it's true. It has more flexibility than I thought. I tested with 4 wheels and now it works (I was doing something wrong). It also works with negative numbers!. Good job! I've found that watching the *.xml, you can read some notes on the library that can be helpful. I still lack experience. With respect to the library, I will wait to learn a bit more. Just one more thing. Can I change the text size of the wheel? Thank you.
derez Expert Licensed User Longtime User Apr 19, 2012 #7 Can I change the text size of the wheel? Click to expand... Use setTextSize(int TextSize) method. When typing the object name and dot you can see all the available methods, and after selection you can see the short explanation about the method.
Can I change the text size of the wheel? Click to expand... Use setTextSize(int TextSize) method. When typing the object name and dot you can see all the available methods, and after selection you can see the short explanation about the method.
JoanRPM Active Member Licensed User Longtime User Apr 19, 2012 #8 Yes, thank you. I've seen. But it works with "wv1.TextSize = 40". With "wv1.TextSize (40)" I get a compile error. Greetings.
Yes, thank you. I've seen. But it works with "wv1.TextSize = 40". With "wv1.TextSize (40)" I get a compile error. Greetings.
derez Expert Licensed User Longtime User Apr 21, 2012 #9 You are right, I'm sorry. I copied the name of the method from the library, but b4a compiles the library and the method is shown as Textsize and works as you wrote.
You are right, I'm sorry. I copied the name of the method from the library, but b4a compiles the library and the method is shown as Textsize and works as you wrote.
D dpalmond Member Licensed User Longtime User Apr 22, 2012 #10 Derez, Thanks for the work on the wheelview. :sign0087: I modified your code some so that if you select Feb on the wheel and the day wheel is past the 28th or 29th(Leap Year), the wheel will correct back to the 28th or 29th. Same for April, June, September, and November. Also, removed the red horizontal lines, and spaced the wheels so there are vertical divider lines for those who like that look. View attachment WheelView2.zip
Derez, Thanks for the work on the wheelview. :sign0087: I modified your code some so that if you select Feb on the wheel and the day wheel is past the 28th or 29th(Leap Year), the wheel will correct back to the 28th or 29th. Same for April, June, September, and November. Also, removed the red horizontal lines, and spaced the wheels so there are vertical divider lines for those who like that look. View attachment WheelView2.zip
derez Expert Licensed User Longtime User Apr 22, 2012 #11 The application is just a demo for the use of the library. Feel free to modify it and suit it to your needs
The application is just a demo for the use of the library. Feel free to modify it and suit it to your needs
alfcen Well-Known Member Licensed User Longtime User Apr 24, 2012 #12 Hi derez, This is a great and versatile start.:sign0098: Would it be much trouble to add leading zeros for numbers under 10 when using WV4.Initialize(svstep,0,23,True ,"wv4") WV5.Initialize(svstep,0,59,True ,"wv5") This would look much smarter when adding time to your wheel. To dpalmond: Your modifications are a nice touch! Attachments jd.png 26.7 KB · Views: 1,091 Last edited: Apr 25, 2012
Hi derez, This is a great and versatile start.:sign0098: Would it be much trouble to add leading zeros for numbers under 10 when using WV4.Initialize(svstep,0,23,True ,"wv4") WV5.Initialize(svstep,0,59,True ,"wv5") This would look much smarter when adding time to your wheel. To dpalmond: Your modifications are a nice touch!
derez Expert Licensed User Longtime User Apr 24, 2012 #13 Robert The initialization method that you used is based on integers (start to end), and it is not much trouble to modify it in the library but then it will not work for the case that you do not want leading zeros ! To get the effect - use a list or an array with the other initialization methods, where the items are strings with leading zeros. To prepare such list or array with a loop assigning numberformat(i,2,0) should be simple.
Robert The initialization method that you used is based on integers (start to end), and it is not much trouble to modify it in the library but then it will not work for the case that you do not want leading zeros ! To get the effect - use a list or an array with the other initialization methods, where the items are strings with leading zeros. To prepare such list or array with a loop assigning numberformat(i,2,0) should be simple.
alfcen Well-Known Member Licensed User Longtime User Apr 24, 2012 #14 David, Understand that. Fair enough, that makes sense. Thanks for your fast reply.
D dpalmond Member Licensed User Longtime User Apr 30, 2012 #15 alfcen said: Hi derez, This is a great and versatile start.:sign0098: Would it be much trouble to add leading zeros for numbers under 10 when using WV4.Initialize(svstep,0,23,True ,"wv4") WV5.Initialize(svstep,0,59,True ,"wv5") This would look much smarter when adding time to your wheel. To dpalmond: Your modifications are a nice touch! Click to expand... Here's how I add leading zeros to the numbers. Create an array to hold the digits calling the FixDigits routine. For I = 0 To valMinutes.Length - 1 valMinutes(I) = FixDigits(I) Next Sub FixDigits(d As Int) As String If d < 10 Then Return "0" & d Else Return d End If End Sub Then add the array to the wheel view like this wvMinutes.Initialize2(svstep,valMinutes,True ,"wvMinutes") Do the same for hours.
alfcen said: Hi derez, This is a great and versatile start.:sign0098: Would it be much trouble to add leading zeros for numbers under 10 when using WV4.Initialize(svstep,0,23,True ,"wv4") WV5.Initialize(svstep,0,59,True ,"wv5") This would look much smarter when adding time to your wheel. To dpalmond: Your modifications are a nice touch! Click to expand... Here's how I add leading zeros to the numbers. Create an array to hold the digits calling the FixDigits routine. For I = 0 To valMinutes.Length - 1 valMinutes(I) = FixDigits(I) Next Sub FixDigits(d As Int) As String If d < 10 Then Return "0" & d Else Return d End If End Sub Then add the array to the wheel view like this wvMinutes.Initialize2(svstep,valMinutes,True ,"wvMinutes") Do the same for hours.
alfcen Well-Known Member Licensed User Longtime User Apr 30, 2012 #16 Thanks for writing, dpalmond, it certainly works. This alternative suffices without involving a sub routine. Code: Copy Dim lstTime as List lstTime.Initialize For i = 0 To 23 lstTime.Add(NumberFormat(i,2,0)) Next WV4.Initialize1(svstep,lstTime,True,"Wheel")
Thanks for writing, dpalmond, it certainly works. This alternative suffices without involving a sub routine. Code: Copy Dim lstTime as List lstTime.Initialize For i = 0 To 23 lstTime.Add(NumberFormat(i,2,0)) Next WV4.Initialize1(svstep,lstTime,True,"Wheel")
derez Expert Licensed User Longtime User May 2, 2012 #17 Update the values while working with the wheel I wanted to update some values during the application runtime. I had to remove the view and re-initialize it with all the display setup so I added two update methods to update the values of an existing wheel. The update may be of shorter or longer size. Also changed the name of SetValue to SetToValue to avoid misunderstandings about its function. see ver 1.1 in the first post. Last edited: May 2, 2012
Update the values while working with the wheel I wanted to update some values during the application runtime. I had to remove the view and re-initialize it with all the display setup so I added two update methods to update the values of an existing wheel. The update may be of shorter or longer size. Also changed the name of SetValue to SetToValue to avoid misunderstandings about its function. see ver 1.1 in the first post.
E eatyourpeas Member Licensed User Longtime User May 13, 2012 #18 Bold Selection Very helpful - enjoying using this library Is there any way that the selected value could be set to bold (or any color) for example, without modifying the whole list? any pointers gratefully received thanks
Bold Selection Very helpful - enjoying using this library Is there any way that the selected value could be set to bold (or any color) for example, without modifying the whole list? any pointers gratefully received thanks
T tpakis Active Member Licensed User Longtime User May 29, 2012 #19 I can't find the demo for the library, maybe it isn't in the zip for version 1.1?
JoanRPM Active Member Licensed User Longtime User May 29, 2012 #20 Here you are a simple expample. Regards. Attachments WheelView.zip WheelView.zip 9.9 KB · Views: 740