D
Deleted member 103
Guest
Hello,
why do you have to define all views for a layout in Sub Global?
I can understand it when the views are in the main layout, but not when it comes to views that are simply added to a customlistview with a layout.
Here is a sub of an Erel example:
The views ImageView1, lblTitle, lblContent, lblAction1 and lblAction2 could also be defined in sub "CreateItem", or what speaks against it?
For example:
why do you have to define all views for a layout in Sub Global?
I can understand it when the views are in the main layout, but not when it comes to views that are simply added to a customlistview with a layout.
Here is a sub of an Erel example:
B4X:
Sub Process_Globals
Private xui As XUI
End Sub
Sub Globals
'These global variables will be redeclared each time the activity is created.
'These variables can only be accessed from this module.
Private CLV1 As CustomListView
Private ImageView1 As B4XView
Private lblTitle As B4XView
Private lblContent As B4XView
Private lblAction1 As Label
Private lblAction2 As Label
End Sub
Sub Activity_Create(FirstTime As Boolean)
'Do not forget to load the layout file created with the visual designer. For example:
Activity.LoadLayout("1")
Activity.AddMenuItem3("", "refresh", xui.LoadBitmapResize(File.DirAssets, "ic_cached_white_24dp.png", 32dip, 32dip, True), True)
Activity.AddMenuItem3("", "done", xui.LoadBitmapResize(File.DirAssets, "ic_done_white_24dp.png", 32dip, 32dip, True), True)
Dim bitmaps As List = Array("pexels-photo-446811.jpeg", "pexels-photo-571195.jpeg", _
"pexels-photo-736212.jpeg", "pexels-photo-592798.jpeg")
For i = 1 To 4
Dim content As String = $"Lorem ipsum dolor sit amet,
consectetur adipiscing elit,
sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat."$
CLV1.Add(CreateItem(CLV1.AsView.Width, $"This is item #${i}"$, bitmaps.Get(i - 1), content), "")
Next
End Sub
Private Sub CreateItem(Width As Int, Title As String, Image As String, Content As String) As Panel
Dim p As B4XView = xui.CreatePanel("")
Dim height As Int = 280dip
If GetDeviceLayoutValues.ApproximateScreenSize < 4.5 Then height = 310dip
p.SetLayoutAnimated(0, 0, 0, Width, height)
p.LoadLayout("Card1")
lblTitle.Text = Title
lblContent.Text = Content
SetColorStateList(lblAction1, xui.Color_LightGray, lblAction1.TextColor)
SetColorStateList(lblAction2, xui.Color_LightGray, lblAction2.TextColor)
ImageView1.SetBitmap(xui.LoadBitmapResize(File.DirAssets, Image, ImageView1.Width, ImageView1.Height, True))
Return p
End Sub
The views ImageView1, lblTitle, lblContent, lblAction1 and lblAction2 could also be defined in sub "CreateItem", or what speaks against it?
For example:
B4X:
Private Sub CreateItem(Width As Int, Title As String, Image As String, Content As String) As Panel
Dim ImageView1 As B4XView
Dim lblTitle As B4XView
Dim lblContent As B4XView
Dim lblAction1 As Label
Dim lblAction2 As Label
Dim p As B4XView = xui.CreatePanel("")
Dim height As Int = 280dip
If GetDeviceLayoutValues.ApproximateScreenSize < 4.5 Then height = 310dip
p.SetLayoutAnimated(0, 0, 0, Width, height)
p.LoadLayout("Card1")
lblTitle.Text = Title
lblContent.Text = Content
SetColorStateList(lblAction1, xui.Color_LightGray, lblAction1.TextColor)
SetColorStateList(lblAction2, xui.Color_LightGray, lblAction2.TextColor)
ImageView1.SetBitmap(xui.LoadBitmapResize(File.DirAssets, Image, ImageView1.Width, ImageView1.Height, True))
Return p
End Sub