First go at a serious cross platform app.
Please help, why does my xCLV work perfectly on B4A but not in B4J
It loads but nothing is visible until I scroll to the bottom and then back to the top. Then it displays a few rows at the top and a few at the bottom but nothing in the middle.
Not sure what I'm doing wrong.
Please help, why does my xCLV work perfectly on B4A but not in B4J
It loads but nothing is visible until I scroll to the bottom and then back to the top. Then it displays a few rows at the top and a few at the bottom but nothing in the middle.
Not sure what I'm doing wrong.
B4X:
#Region Shared Files
#CustomBuildAction: folders ready, %WINDIR%\System32\Robocopy.exe,"..\..\Shared Files" "..\Files"
'Ctrl + click to sync files: ide://run?file=%WINDIR%\System32\Robocopy.exe&args=..\..\Shared+Files&args=..\Files&FilesSync=True
#End Region
'Ctrl + click to export as zip: ide://run?File=%B4X%\Zipper.jar&Args=Project.zip
Sub Class_Globals
#if b4j
Private fx As JFX
#End If
Private Root As B4XView
Private xui As XUI
Private ivTools As B4XView
Private ivVIN As B4XView
'Private B4XTxtSearch As B4XFloatTextField
Private ivAddCar As B4XView
Private WobbleMenu1 As WobbleMenu
Private clvMakes As CustomListView
Private sql1 As SQL
Private CachedPanels As List
Type ImageData (FileName As String, Title As String, Bitmap As B4XBitmap, Model As Int)
End Sub
Public Sub Initialize
' B4XPages.GetManager.LogEvents = True
End Sub
'This event will be called once, before the page becomes visible.
Private Sub B4XPage_Created (Root1 As B4XView)
Root = Root1
Root.LoadLayout("MainPage")
#if b4j
WobbleMenu1.SetTabTextIcon(1,"Cars",Chr(0xF1B9), fx.CreateFontAwesome(24))
WobbleMenu1.SetTabTextIcon(2,"Bikes",Chr(0xF21C),fx.CreateFontAwesome(24))
WobbleMenu1.SetTabTextIcon(3,"Trucks",Chr(0xF0D1),fx.CreateFontAwesome(24))
WobbleMenu1.SetTabTextIcon(4,"Other",Chr(0xF074),fx.CreateFontAwesome(24))
WobbleMenu1.SetTabTextIcon(5,"Messages",Chr(0xF1D7),fx.CreateFontAwesome(24))
WobbleMenu1.SetBadge(5,3,fx.Colors.White,fx.Colors.Blue)
#end if
#if b4a
'Typeface.DEFAULT
WobbleMenu1.SetTabTextIcon(1,"Cars",Chr(0xF1B9), Typeface.DEFAULT)
WobbleMenu1.SetTabTextIcon(2,"Bikes",Chr(0xF21C),Typeface.DEFAULT)
WobbleMenu1.SetTabTextIcon(3,"Trucks",Chr(0xF0D1),Typeface.DEFAULT)
WobbleMenu1.SetTabTextIcon(4,"Other",Chr(0xF074),Typeface.DEFAULT)
WobbleMenu1.SetTabTextIcon(5,"Messages",Chr(0xF1D7),Typeface.DEFAULT)
WobbleMenu1.SetBadge(5,3, Colors.White,Colors.Blue)
#End If
'------File-------
xui.SetDataFolder("sql example") 'required in B4J
Dim dbname As String = "helper.db"
If File.Exists(xui.DefaultFolder, dbname) = False Then File.Copy(File.DirAssets, dbname, xui.DefaultFolder, dbname)
#if B4J
'B4J SQL object can access many types of databases (same as B4A JdbcSQL).
sql1.InitializeSQLite(xui.DefaultFolder, dbname, False)
#else
sql1.Initialize(xui.DefaultFolder, dbname, False)
#End If
End Sub
Sub B4XPage_Appear
LoadMakes
End Sub
#REGION Button Clicks
Private Sub B4XTxtSearch_TextChanged (Old As String, New As String)
End Sub
#if b4j
Private Sub ivVIN_MouseClicked (EventData As MouseEvent)
End Sub
Private Sub ivTools_MouseClicked (EventData As MouseEvent)
End Sub
Private Sub ivAddCar_MouseClicked (EventData As MouseEvent)
End Sub
#end if
#if b4a
Private Sub ivAddCar_Click
End Sub
#end if
#End Region
#REGION WobbleMenu1
Private Sub WobbleMenu1_Tab1Click
LoadMakes
End Sub
Private Sub WobbleMenu1_Tab2Click
LoadMakes
End Sub
Private Sub WobbleMenu1_Tab3Click
End Sub
Private Sub WobbleMenu1_Tab4Click
End Sub
Private Sub WobbleMenu1_Tab5Click
End Sub
#End Region
'Private Sub iv1_MouseClicked (EventData As MouseEvent)
'End Sub
#Region Make List View
Sub LoadMakes()
Dim makeType As Int = WobbleMenu1.GetCurrentTab
Dim makeList As Map
CachedPanels.Initialize
makeList.Initialize
clvMakes.Clear
Dim rs As ResultSet = sql1.ExecQuery("SELECT * FROM VehicleMakes WHERE EXISTS (Select 1 FROM Vehicles WHERE Vehicles.MakeID = VehicleMakes.MakeID) AND VehicleType = " & makeType & " ORDER BY LOWER(MakeName)")
Do While rs.NextRow
makeList.Put(rs.GetString("MakeName"),rs.GetLong("MakeID"))
Loop
rs.Close
CachedPanels.Initialize
Dim rows As Int = makeList.Size/4 ' number of makes / 4
Dim remainder As Int = makeList.Size Mod 4 ' if does not divide by four then add 1 more row
If remainder > 0 Then
rows = rows + 1
End If
Dim counter As Int = makeList.Size
Dim makeCounter As Int = 0
For i = 1 To rows
If counter > 3 Then
Dim id1 As ImageData = CreateItem2(makeList.GetKeyAt(makeCounter),makeList.GetValueAt(makeCounter))
Dim id2 As ImageData = CreateItem2(makeList.GetKeyAt(makeCounter+1),makeList.GetValueAt(makeCounter+1))
Dim id3 As ImageData = CreateItem2(makeList.GetKeyAt(makeCounter+2),makeList.GetValueAt(makeCounter+2))
Dim id4 As ImageData = CreateItem2(makeList.GetKeyAt(makeCounter+3),makeList.GetValueAt(makeCounter+3))
counter = counter - 4
makeCounter = makeCounter + 4
Else
If counter = 3 Then
Dim id1 As ImageData = CreateItem2(makeList.GetKeyAt(makeCounter),makeList.GetValueAt(makeCounter))
Dim id2 As ImageData = CreateItem2(makeList.GetKeyAt(makeCounter+1),makeList.GetValueAt(makeCounter+1))
Dim id3 As ImageData = CreateItem2(makeList.GetKeyAt(makeCounter+2),makeList.GetValueAt(makeCounter+2))
Dim id4 As ImageData = CreateItem2("",0)
counter = counter - 3
makeCounter = makeCounter + 3
'id4.Title = ""
'id4.Bitmap = Null
End If
If counter = 2 Then
Dim id1 As ImageData = CreateItem2(makeList.GetKeyAt(makeCounter),makeList.GetValueAt(makeCounter))
Dim id2 As ImageData = CreateItem2(makeList.GetKeyAt(makeCounter+1),makeList.GetValueAt(makeCounter+1))
Dim id3 As ImageData = CreateItem2("",0)
Dim id4 As ImageData = CreateItem2("",0)
counter = counter - 2
makeCounter = makeCounter + 2
'id4.Title = ""
'id3.Title = ""
'id4.Bitmap = Null
'id3.Bitmap = Null
End If
If counter = 1 Then
Dim id1 As ImageData = CreateItem2(makeList.GetKeyAt(makeCounter),makeList.GetValueAt(makeCounter))
Dim id2 As ImageData = CreateItem2("",0)
Dim id3 As ImageData = CreateItem2("",0)
Dim id4 As ImageData = CreateItem2("",0)
counter = counter - 1
makeCounter = makeCounter + 1
'id4.Title = ""
'id4.FileName = ""
'id3.FileName = ""
'id2.FileName = ""
'id3.Title = ""
'id2.Title = ""
End If
End If
Dim p As B4XView = xui.CreatePanel("")
p.SetLayoutAnimated(0, 0, 0, clvMakes.AsView.Width, 110dip)
clvMakes.Add(p, Array As ImageData(id1, id2, id3, id4))
Next
End Sub
Sub CreateItem2 (Title As String, Model As Int) As ImageData
Dim id As ImageData
id.Initialize
If Title.EndsWith("Truck") Then
id.FileName = Title.ToLowerCase.SubString2(0,Title.Length - 6) & ".png" '"isuzu.png"
Else
id.FileName = Title.ToLowerCase & ".png"
End If
id.Title = Title
id.Model = Model
Log("Title - " & Title)
Log("Model- " & Model)
Return id
End Sub
Private Sub clvMakes_VisibleRangeChanged (FirstIndex As Int, LastIndex As Int)
Dim ExtraSize As Int = 10
For i = 0 To clvMakes.Size - 1
Dim p As B4XView = clvMakes.GetPanel(i)
Dim ids() As ImageData = clvMakes.GetValue(i)
If i >= Max(0, FirstIndex - ExtraSize) And i <= Min(LastIndex + ExtraSize, clvMakes.Size - 1) Then
If p.NumberOfViews = 0 Then
GetPanelFromCache(p)
End If
If ids(0).Bitmap.IsInitialized = False Then
For index = 0 To 3
If ids(index).Model > 0 Then
ids(index).Bitmap = xui.LoadBitmapResize(File.DirAssets, ids(index).FileName, p.GetView(0).GetView(index).Width, p.GetView(0).GetView(index).Height, True)' p.Width / 4, p.Height, True)
p.GetView(0).GetView(index).SetBitmap(ids(index).Bitmap)
p.GetView(0).GetView(index).Tag = ids(index).Model
p.GetView(0).GetView(index + 4).Text = ids(index).Title
Else
p.GetView(0).GetView(index).Visible=False
End If
Next
End If
Else
If p.NumberOfViews = 0 Then Continue
If ids(0).Bitmap.IsInitialized Then
For index = 0 To 3
p.GetView(0).GetView(index).SetBitmap(Null)
ids(index).Bitmap = Null
Next
Dim PanelWithViews As B4XView = p.GetView(0)
PanelWithViews.RemoveViewFromParent
CachedPanels.Add(PanelWithViews)
End If
End If
Next
End Sub
Sub GetPanelFromCache (Parent As B4XView)
If CachedPanels.Size = 0 Then
Parent.LoadLayout("MakeRowLayout")
' Log("create item")
Else
Dim p As B4XView = CachedPanels.Get(CachedPanels.Size - 1)
CachedPanels.RemoveAt(CachedPanels.Size - 1)
Parent.AddView(p, 0, 0, Parent.Width, Parent.Height)
End If
End Sub
Sub FindExapnded As Int 'ignore
For i = 0 To clvMakes.GetSize - 1
If clvMakes.GetPanel(i).Tag = True Then Return i
Next
Return -1
End Sub
#end region