B4J Tutorial [B4X] Custom Views with Enhanced Designer Support

Status
Not open for further replies.

LucaMs

Expert
Licensed User
Longtime User

and perhaps other common properties, like:
B4X:
#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:

Hugh Thomas

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

Mashiane

Expert
Licensed User
Longtime User
Thanks for Clarity ... as a goodie another small Custom View attached: ButtonTextField.
View attachment 40756
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
 

Cableguy

Expert
Licensed User
Longtime User
you need to create an "AddToParent" method, and re-create the view in it by adding your custom view to the passed parent
 

klaus

Expert
Licensed User
Longtime 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.
 

rwblinn

Well-Known Member
Licensed User
Longtime 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
B4X:
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.
 

Attachments

  • B4JHowToCustomViewLabeledTextField.zip
    4.2 KB · Views: 589

klaus

Expert
Licensed User
Longtime 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.
 

Attachments

  • B4JHowToCustomViewLabeledTextField_New.zip
    3.8 KB · Views: 612

rwblinn

Well-Known Member
Licensed User
Longtime 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:
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…