B4J Question custom view help and type of project question

Daren463

Member
Licensed User
B4J has changed a LOT since I first looked into programming with it, so I would like to ask for some advice. I would like to write a program that the user would drag and drop several different types custom views as shown below. I am unsure of what type of B4J project I would need to use.

nodes.PNG

I had stared a project in an older version of B4j then updated. I am ASSUMING it was converted into a page.
I am also trying to show my newly created custom view in my work panel without success. Below is the code.

B4X:
Sub Process_Globals
    Private fx As JFX
    Private MainForm As Form
    Private MenuBar1 As MenuBar

    Private Selectors As Selector
    Private btn_Clear As Button
    Private pnl_Info As Pane
    Private pnl_Tools As Pane
    Private pnl_Work As Pane
    Private txt_Info As TextArea
End Sub

Sub AppStart (Form1 As Form, Args() As String)
    MainForm = Form1
    MainForm.RootPane.LoadLayout("Layout1") 'Load the layout file.
    MainForm.Show
    MainForm.Title = "Behevior Tree"
    Selectors.Initialize(Me,"Selectors")
    Selectors.AddToParent(pnl_Work,0,0,170,270)
   
End Sub

B4X:
''Custom View class
'#Event: ExampleEvent (Value As Int)
'#DesignerProperty: Key: BooleanExample, DisplayName: Boolean Example, FieldType: Boolean, DefaultValue: True, Description: Example of a boolean property.
'#DesignerProperty: Key: IntExample, DisplayName: Int Example, FieldType: Int, DefaultValue: 10, MinRange: 0, MaxRange: 100, Description: Note that MinRange and MaxRange are optional.
'#DesignerProperty: Key: StringWithListExample, DisplayName: String With List, FieldType: String, DefaultValue: Sunday, List: Sunday|Monday|Tuesday|Wednesday|Thursday|Friday|Saturday
'#DesignerProperty: Key: StringExample, DisplayName: String Example, FieldType: String, DefaultValue: Text
'#DesignerProperty: Key: ColorExample, DisplayName: Color Example, FieldType: Color, DefaultValue: 0xFFCFDCDC, Description: You can use the built-in color picker to find the color values.
'#DesignerProperty: Key: DefaultColorExample, DisplayName: Default Color Example, FieldType: Color, DefaultValue: Null, Description: Setting the default value to Null means that a nullable field will be displayed.
Sub Class_Globals
    Private fx As JFX
    Private mEventName As String 'ignore
    Private mCallBack As Object 'ignore
    Private mBase As Pane
    Private btn_Lower As B4XView
    Private btn_Upper As B4XView
    Private pnl_Background As B4XView
    Private pnl_Ring As B4XView
    Private txt_Description As B4XView
    Private txt_ID As B4XView
    Private txt_Name As B4XView
    Private txt_Type As B4XView
End Sub

Public Sub Initialize (Callback As Object, EventName As String)
    mEventName = EventName
    mCallBack = Callback
End Sub

Public Sub DesignerCreateView (Base As Object, Lbl As Label, Props As Map)
    mBase = Base
   
    'Sleep(0)
    mBase.LoadLayout("SelectorView")
    'CallSubDelayed2(Me, "SelectorView", Props)
End Sub

Private Sub Base_Resize (Width As Double, Height As Double)
   
End Sub

Public Sub GetBase As Pane
    Return mBase
End Sub

Public Sub AddToParent(Parent As B4XView, Left As Int, Top As Int, Width As Int, Height    As Int)
    mBase.Initialize("mBase")
    Parent.AddView(mBase, Left, Top, Width, Height)
End Sub
 

Andrew (Digitwell)

Well-Known Member
Licensed User
Your code is not the way to add a custom view to a screen. The view will not be created correctly as the DesignerCreateView function is not called.

Custom views should be added via a layout.

see :
 
Upvote 0

Daren463

Member
Licensed User
Andrew, I looked at your example but is for B4A and it dose not show the DesignerCreateView function being used. Ive looked for examples and have not found any.

Thanks to all who replied.
 
Upvote 0

Andrew (Digitwell)

Well-Known Member
Licensed User
DesignerCreateView is called automatically for all custom views which are part of a layout.

Take a look at this tutorial.

There is also this booklet on the subject.

 
Upvote 0

Daren463

Member
Licensed User
I think i ran down the same rabbit hole as the fellow in the link below. Fortunately he posted the solution.
Thanks again for the help.

 
Upvote 0
Top