B4A Library WheelView Library

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:

moster67

Expert
Licensed User
Longtime User
Thank you Derez, :icon_clap:

just tested your demo and it works nicely.
 

JoanRPM

Active Member
Licensed User
Longtime User
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
but not if you make more than 3
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.
This is up to you - you can set the layout with spaces between the wheels (in the application,not the library), here:
B4X:
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):
B4X:
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?
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, ...
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
    scr2.png
    24 KB · Views: 800
  • scr3.png
    scr3.png
    45.1 KB · Views: 1,023
Last edited:

JoanRPM

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

derez

Expert
Licensed User
Longtime User
Can I change the text size of the wheel?

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
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
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.
 

dpalmond

Member
Licensed User
Longtime User
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
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
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
    jd.png
    26.7 KB · Views: 507
Last edited:

derez

Expert
Licensed User
Longtime User
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
David,
Understand that. Fair enough, that makes sense.
Thanks for your fast reply.
 

dpalmond

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

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
Thanks for writing, dpalmond, it certainly works.
This alternative suffices without involving a sub routine.


B4X:
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
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:

eatyourpeas

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

tpakis

Active Member
Licensed User
Longtime User
I can't find the demo for the library, maybe it isn't in the zip for version 1.1?
 
Top