B4A Class [B4X] [class] xWheel

Xwheel is a "rotating wheel" based on xCustomListView.

I tested this class in B4A, but not currently having a MAC, could you tell me if it is compatible with B4i ?

xWheel
Author: @mberthe
Version: 1.2

Dependancies :

B4A : XUI,JavaObjet,StringUtils,xCustomLisView,BipmapCreator


Usage:
  1. Load in the designer the layout xWheelTemplate with the xCustomLIistView : CLV1
  2. In the designer create a instance of the custom view : xWheel1 (layout 1) and set the custom properties :
    • ItemHeight : set the items height (default value : 25dip)
    • NbItem : set the number of visible items : (default value : 7)
    • TextSize : set the item text size (default value : 14)
    • TextColor : set the item text color (default value : Black)
    • BorderWidth : set the border width (default value : 5dip)
    • BorderColor : set the border color (default value : LightGray )
  3. Initialtize the list of items : list1 (elements text & val)
  4. draw the xwheel
    B4X:
    xWheel1.initwheel[(list1)

    Properties:
    ItemIndex : set the preselected item (default value : 1)​
    Methode :
    xwheel1.UpdateItems(nlist as List) : change the items list​

    Events:
    xwheel1_scroll(index As Int,value As String) :​
    get the index(base 1) and the value of the selected item​


    Update:
    version 1.1 : fixed issues of cross platform compatibility
    version 1.2 : creation of the cusom view "xwheel"​
 

Attachments

  • xwheel_example_1_2.zip
    12.7 KB · Views: 203
  • xwheel.bas
    5.7 KB · Views: 192
Last edited:

Erel

B4X founder
Staff member
Licensed User
Longtime User
Nice!

Tips:
1. Better to move tlist1 declaration to xwheel. It is also better to change its name so it is clear that it belongs to xwheel.
2. CreateListItem is not cross platform. It should be changed to:
B4X:
private Sub CreateListItem(Text As String, Width As Int, Height As Int) As B4XView
   Dim p As B4XView = xui.CreatePanel("")
   Dim l As Label
   Dim xl As B4XView = l
   p.SetLayoutAnimated(0, 0, 0, Width, Height)
   p.Color=xui.Color_Transparent
   l.Initialize("L")
   xl.SetTextAlignment("CENTER", "CENTER")   
   p.AddView(xl, 0, 0, Width, Height)
   xl.color=xui.Color_Transparent
   xl.TextColor=xui.Color_black
   xl.TextSize=mTextSize
   xl.Text = Text
   Return p
End Sub

3. SubExists is not cross platform. You should use XUI.SubExists:
B4X:
If xui.SubExists(mCallback,mEventName & "_scroll", 2) Then
   CallSub3(mCallback, mEventName & "_scroll", find+1, val)
End If

4. It would have been easier to use this view if you implemented it as a custom view and loaded a layout file with CustomListView inside the class code (in DesignerCreateView after calling Sleep(0)).

5. Passing -1 to the width and height will only work in Android:
B4X:
panel1.AddView(mclv.AsView,-1,-1,-1,-1)
 

mberthe

Member
Licensed User
Longtime User
Thank you very much @Erel for the tips.
I fixed the cross plaform compatibility issues in post #1 (update 1.1).
On the other hand, I do not know how to implement this view as a custom view in the class (tip 4): would there be an example of customview with a customlistview ?
 

mberthe

Member
Licensed User
Longtime User

Attachments

  • xwheel.b4xlib
    3.6 KB · Views: 175
Top