Android Question B4Xview and a view class development

peacemaker

Expert
Licensed User
Longtime User
HI, All

For any new visual view in B4A I prefer to have the source code class, so trying to study how to correctly create view classes.
Now i'm trying to change CLVSwipe class. I see that it's recommended to use only the latest B4X objects and so on...

But for a view creation in a class - i prefer not to have the inteface layout file, if the interface is simple - just 1 or 2 views are required, so - just to create the panel (and 1-2 views) by the class code.
But the panel container must be initialized firstly. Please, help to understand how to initialize the class interface correctly without loading layouts.

B4X:
'version 0.1
Sub Class_Globals
    Private mWV As WebView
    Public Base As B4XView
    Private TouchXStart, TouchYStart As Float
    Private HandlingSwipe As Boolean
    Private xui As XUI
    Private mCallback As Object
    Private mEventName As String
    Private mPullToRefreshPanel As B4XView
    Private PullToRefreshSwipe As Boolean 'ignore
    Private WaitingForRefreshToComplete As Boolean
    Private mActivity As Activity
    Private ProgressBar1 As B4XView
End Sub

Public Sub Initialize (Activity As Activity, cWV As WebView, Callback As Object, EventName As String)
    mActivity = Activity
    Dim creator As TouchPanelCreator
    Base = creator.CreateTouchPanel("TouchPanel")
    Dim p As B4XView = xui.CreatePanel("")
    p.SetLayoutAnimated(0, 0, 0, 1dip, 1dip)
    mWV = cWV
    Dim p1 As B4XView = mWV.Parent
    p1.AddView(Base, mWV.Left, mWV.Top, mWV.Width, mWV.Height)
    mWV.RemoveView
    Base.AddView(mWV, 0, 0, Base.Width, Base.Height)
    mCallback = Callback
    mEventName = EventName
    Dim p2 As B4XView = xui.CreatePanel("")
    p2.SetLayoutAnimated(0, 0, 0, 100%x, 70dip)
    p1.AddView
    setPullToRefreshPanel(p2)
    mPullToRefreshPanel.AddView(ProgressBar1, 0, 0, 50dip, 50dip)
End Sub

Private Sub setPullToRefreshPanel(pnl As B4XView)
    If pnl.Parent.IsInitialized Then pnl.RemoveViewFromParent
    If mPullToRefreshPanel.IsInitialized Then mPullToRefreshPanel.RemoveViewFromParent
    mPullToRefreshPanel = pnl
    Base.AddView(mPullToRefreshPanel, 0, 0, Base.Width, mPullToRefreshPanel.Height)
    mPullToRefreshPanel.SendToBack
    mPullToRefreshPanel.Visible = False
End Sub

Here i need to add the progressbar into p2 panel, that is added on to the Base panel, but p2 is not initialized.

Or XUI crossplatform idea is that all 3 platform must be inited only via layout loading and creating views by code is impossible ?
 
Last edited:

peacemaker

Expert
Licensed User
Longtime User
it easier to create the layout with the designer, especially in B4J and B4i

But if layout is simplest, and just 1-2 view: how to create and init them by code in the class?
I like idea to create the lib, but do not like that depending on layout files. For complex interface it's OK, but for simple - i'd like to avoid.
I see that b4xlib format is good now for layout also, but ... i'd like to study how to do without layout files.
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Create panels with XUI.CreatePanel.
Most other views should be created with platform specific code:
B4X:
Dim x As B4XView
#if B4A OR B4J
 Dim b As Button
 b.Initialize("")
#else if B4i
 Dim b As Button
 b.Initialize(..., ...)
#End If
x = b

Nothing bad with using platform specific code.
 
Upvote 0

peacemaker

Expert
Licensed User
Longtime User
OK, thanks, Erel.
In this thread i tried to load the ProgressBar without the layout file. And could not to do it, due to some initialization of view or parent was required. It's your CLVSwipe class, where i tried to avoid the layout file.
 
Upvote 0
Top