B4J Tutorial [B4X] Custom Views with Enhanced Designer Support

Discussion in 'B4J Tutorials' started by Erel, Jan 18, 2016.

Thread Status:
Not open for further replies.
  1. LucaMs

    LucaMs Expert Licensed User

    and perhaps other common properties, like:
    Code:
    #Region  + PROPERTIES

    Public Sub setTag(Tag As String)
        mBase.Tag = Tag
    End Sub
    Public Sub getTag As String
        
    Return mBase.Tag
    End Sub

    Public Sub setVisible(Visible As Boolean)
       mBase.Visible = Visible
    End Sub
    Public Sub getVisible As Boolean
       
    Return mBase.Visible
    End Sub

    Public Sub setEnabled(Enabled As Boolean)
       mBase.Enabled = Enabled
       
    For Each v As View In mBase.GetAllViewsRecursive
         v.Enabled = Enabled
       
    Next
    End Sub
    Public Sub getEnabled As Boolean
       
    Return mBase.Enabled
    End Sub

    #End Region
    setEnabled should be different in B4J, of course (I think in B4I too, I don't know)


    P.S. I have also a panel on my custom view, same size of Base panel. I use it to change the "disabled look" of my custom view, setting its color to ARGB(160, 0, 0, 0) and to raise the view Click (the view is enabled and then the panel color is Transparent).
    Perhaps also these "features" should be in all custom views as default.

    Uhm... I'm thinking I should post my template (a Forum for members' templates? Or should we use the Snippets Forum?)
     
    Last edited: Jun 17, 2016
  2. Hugh Thomas

    Hugh Thomas Member Licensed User

    Is it possible to change the layout values (left, top, width, height) of the Base panel in B4i? I'm working on a CustomView that adjusts the base panel layout values depending on the value of the customview's designer properties. This works in B4A, but in B4i changing base panel layout values has no effect.

    Hugh
     
  3. Erel

    Erel Administrator Staff Member Licensed User

    Please start a new thread for this in B4i forum.
     
  4. Mashiane

    Mashiane Expert Licensed User

    I would like to add the ButtonTextField control in code and set properties like Tag, Width and also return these. Have done a little adjustment to it for those properties. How do I fix it so that I can add it to a control via code e.g. initialize etc?

    Thanks
     
  5. Cableguy

    Cableguy Expert Licensed User

    you need to create an "AddToParent" method, and re-create the view in it by adding your custom view to the passed parent
     
  6. klaus

    klaus Expert Licensed User

    You need to add a routine in the class to add the CustomView to a parent.

    Have a look HERE, in the B4A forum, it was a similar question.

    You may have a look at chapter 12.4 Custom views in the B4A User's Gude.
    And especially chapter 12.4.2 Adding a custom view by code.
    There you find an example of a CustomView which can also be added in the code.

    The CustomView principles are the same for B4A, B4i and B4J.
     
  7. rwblinn

    rwblinn Well-Known Member Licensed User

    Hi,

    thanks for the additional information .. still learning how to create B4J custom views properly.
    Based on B4A user guide, updated & tested attached example LabeledTextField with a second label created via code.
    In the Custom View class added
    Code:
    Public Sub AddToParent(Parent As Pane, Left As Int, Top As Int, Width As Int, Height As Int)
    which includes creating of the used views label and textfield. The properties of those are set in the main module.

    Let me know if this was done correctly.
     

    Attached Files:

  8. klaus

    klaus Expert Licensed User

    Yes it's the right way.

    One comment:
    You use this routine:
    Public Sub SetLabelText(v As String)
    lblField.Text = v
    End Sub

    And in the calling module:
    LabeledTextField2.SetLabelText("Enter 2:")

    You may use this routine:
    Public Sub setLabelText(LabelText As String)
    lblField.Text = LabelText
    End Sub

    And in the calling module:
    LabeledTextField2.LabelText = "Enter 2:"

    When using SetLabelText it is considered as a routine, S upper case.
    When using setLabelText it is considered as a property, s lower case.

    The same with GetXXX and getXXX.

    Attached a modified version with some other suggestions.
     

    Attached Files:

  9. rwblinn

    rwblinn Well-Known Member Licensed User

    Thanks a lot for the additional modifications - very well explained. Will update the B4JHowTo Examples for Custom Views accordingly = done.

    Been of great help - Appreciated.
     
    Last edited: Oct 10, 2016
    inakigarm likes this.
Thread Status:
Not open for further replies.
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