B4A Class [B4X] [class] xWheel

Discussion in 'Additional libraries, classes and official updates' started by mberthe, Jul 19, 2019.

  1. mberthe

    mberthe Member Licensed User

    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 textsize (default value : 14)
      • TextColor : set the item textsize (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 (elements text & val)

    4. draw the xwheel
      Code:
      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"​
     

    Attached Files:

    Last edited: Aug 2, 2019
  2. Erel

    Erel Administrator Staff Member Licensed 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:
    Code:
    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(
    000, Width, Height)
       p.Color=xui.Color_Transparent
       l.Initialize(
    "L")
       xl.SetTextAlignment(
    "CENTER""CENTER")   
       p.AddView(xl, 
    00, 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:
    Code:
    If xui.SubExists(mCallback,mEventName & "_scroll"2Then
       
    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:
    Code:
    panel1.AddView(mclv.AsView,-1,-1,-1,-1)
     
    mberthe likes this.
  3. mberthe

    mberthe Member Licensed 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 ?
     
  4. Erel

    Erel Administrator Staff Member Licensed User

    mberthe likes this.
  5. mberthe

    mberthe Member Licensed User

    Following @Erel advice, I rewrote the xwheel class by adding a custom view "xwheel" ; See in post #1 the modified class.
    I tried to create a b4xlib (see below the xwheel.b4xlib file) but custom properties do not appear in the custom view; On the other hand, the default properties set by the "#DesignerProperty" are well taken into account !
     

    Attached Files:

    Erel likes this.
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice