Hello all
Just to be sure I´m not doing something wrong or not advisable or merely stupid. This is a skeleton of what I'm doing.
What I want is to create a custom view that goes multiple times inside of another custom view and to generate all this CustomViews by code.
The code seems to work. It is the result of I´mNotGoingToSayHowManyHoursCauseItAshamedMe
. Trust me, I have searched the forum. All I have found was isolated bits of the answer.
Perhaps I have not typed the right words or have not found the right tutorial
Here it goes.
And now the questions:
Is this the right way of doing?
Is the line highlighted en cvTiny what I he found to be called "Code Tag" and is that correctly used?
Why is it not recommended to use a function inside the CustomView to add the view to a parent as I have seen by LucaMs and others?
And the big one (although I have already seen the Erel´s answer in another thread): Why not include an AddView method to CustomViews? More a wish than a question I suppose.
Thank you in advance.
Just to be sure I´m not doing something wrong or not advisable or merely stupid. This is a skeleton of what I'm doing.
What I want is to create a custom view that goes multiple times inside of another custom view and to generate all this CustomViews by code.
The code seems to work. It is the result of I´mNotGoingToSayHowManyHoursCauseItAshamedMe
Perhaps I have not typed the right words or have not found the right tutorial
Here it goes.
Inside CustomView. Call it cvTiny:
Sub Class_Globals
Private mEventName As String 'ignore
Private mCallBack As Object 'ignore
Private mBase As B4XView 'ignore
Private xui As XUI 'ignore
Private mLinkedData As classData1
Private mLabel1 As Label
End Sub
Public Sub Initialize (Callback As Object, EventName As String)
mEventName = EventName
mCallBack = Callback
mLabel1.Initialize("")
End Sub
Public Sub DesignerCreateView (Base As Object, Lbl As Label, Props As Map)
mBase = Base
mBase.Tag = Me 'Is this what is called "Code Tag" in some references???
mBase.AddView(mLabel1, 0, 0, 0, 0)
End Sub
Private Sub Base_Resize (Width As Double, Height As Double)
mBase.Width = Width
mBase.Height = Height
mLabel1.SetLayout(5dip, 5dip, mBase.Width - 10dip, mBase.Height - 10dip)
End Sub
Public Sub getLeft As Int
Return mBase.Left
End Sub
Public Sub setLeft(Value As Int)
mBase.Left = Value
End Sub
Public Sub getWidth As Int
Return mBase.Width
End Sub
Public Sub setWidth(Value As Int)
mBase.Width = Value
Base_Resize (mBase.Width, mBase.Height)
End Sub
Public Sub getLinkedData As classData
Return mLinkedData
End Sub
Public Sub setLinkedData(Value As classData1)
mLinkedData = Value
mLabel1.Text = mLinkedData.Text
End Sub
Outside CustomView. Call it cvBig:
Sub Class_Globals
Private mEventName As String 'ignore
Private mCallBack As Object 'ignore
Private mBase As B4XView 'ignore
Private xui As XUI 'ignore
Public mLinkedData As classData2
Private mPanels(10) As Panel
Private mTinys(10) As cvTiny
End Sub
Public Sub Initialize (Callback As Object, EventName As String)
mEventName = EventName
mCallBack = Callback
For i=0 To 9
mPanels(i).Initialize("")
Next
End Sub
Public Sub DesignerCreateView (Base As Object, Lbl As Label, Props As Map)
mBase = Base
mBase.Tag = Me
CallSubDelayed(Me, "DelayedCreateView") 'Delayed because it needs the view to be completely created before I can use it for the inside views
End Sub
Private Sub DelayedCreateView
For i=0 To 9
mBase.AddView(Panels(i), 2dip, 2dip + (i * 50dip), mBase.Width - 4dip, 20dip)
mPanels(i).LoadLayout("cvTiny")
mTinys(i) = mPanels(i).GetView(0).Tag
Next
End Sub
Private Sub Base_Resize (Width As Double, Height As Double)
mBase.Width = Width
mBase.Height = Height
End Sub
Public Sub getLinked As classData2
Return mLinkedData
End Sub
Public Sub setLinkedData(Value As classData2)
mLinkedData = Value
For i=0 To 9
mTinys(i).LinkedData = mLinkedData.mData(i)
Next
End Sub
And now the questions:
Is this the right way of doing?
Is the line highlighted en cvTiny what I he found to be called "Code Tag" and is that correctly used?
Why is it not recommended to use a function inside the CustomView to add the view to a parent as I have seen by LucaMs and others?
And the big one (although I have already seen the Erel´s answer in another thread): Why not include an AddView method to CustomViews? More a wish than a question I suppose.
Thank you in advance.