iOS Question CLV seems to have gravity 1st row not at top

tsteward

Well-Known Member
Licensed User
Longtime User
My CLV seems to have gravity and when there are only a few rows they sit at the bottom of the view.
If I tilt the phone, then back again, they come to the top.

How do I fix this please?
 

Attachments

  • IMG_0001.PNG
    IMG_0001.PNG
    105.8 KB · Views: 108

tsteward

Well-Known Member
Licensed User
Longtime User
Okay I have 2 CLV's which I added in the designer. If the second CLV has no data to display I want to set it to not visible and CLV1 will use the screen space of both CLV's

What is the right way to achieve this please?
 
Upvote 0

tsteward

Well-Known Member
Licensed User
Longtime User
If I remove all resizing code and only let the designer take care of it I still get the same result in B4I
B4A works fine
 
Upvote 0

tsteward

Well-Known Member
Licensed User
Longtime User
I have removed any manual resizing and only let the designer take control, yet My IOS CustomListViews still start from the bottom.
Can't for the life of me figure out why.
Here is the page code if it helps. Can't put whole app up here as too big and contains server passwords etc.
B4X:
Sub Class_Globals
    Private Root As B4XView 'ignore
    Private xui As XUI 'ignore
    Private clvModels As CustomListView
    
    Type carSearch(CMake As String, CModel As String, CID As Int, CFrom As String, CKey As String, CChip As String,CTool As Boolean)
    Private currentMakeName As String
    Dim haveToolKeyway As List
    Private ivHaveLishi As B4XView
    Private schLblChip As B4XView
    Private schLblKeyway As B4XView
    Private schLblModel As B4XView
    Dim bg As B4XBitmap
    Public B4XFTxtSearch As B4XFloatTextField
    Public clvAKAModels As CustomListView
    Private lblAKA As B4XView
    Private clvIsAKA As Boolean = False
    Private ivAddVehicle As B4XView
End Sub

'You can add more parameters here.
Public Sub Initialize As Object
    Return Me
End Sub

'This event will be called once, before the page becomes visible.
Private Sub B4XPage_Created (Root1 As B4XView)
    Root = Root1
    'load the layout to Root
    Root.LoadLayout("CarModelsLayout")
    bg = xui.LoadBitmap(File.DirAssets, "minilishi.png")
    
End Sub

Sub B4XPage_Appear
    Wait For (setup) Complete (Success As Boolean)
End Sub

Sub setup() As ResumableSub
    'build a list of tools we have
    haveToolKeyway.Initialize
    For i = 0 To B4XPages.MainPage.MyTools.Size - 1
        Dim rs As ResultSet = Main.sql1.ExecQuery2("SELECT * from Tool WHERE ToolID == ?", Array As String(B4XPages.MainPage.MyTools.Get(i)))
        Do While rs.NextRow
            If haveToolKeyway.IndexOf(rs.GetString("KeyblankID")) < 0 Then
                haveToolKeyway.Add(rs.GetString("KeyblankID"))
            End If
        Loop
        rs.Close
    Next
    If B4XPages.MainPage.searchString.Length > 2 Then
        B4XPages.SetTitle(Me,"Searching...")
        B4XFTxtSearch.Text = B4XPages.MainPage.searchString
        #If B4A
        Dim Disp1 As EditText = B4XFTxtSearch.TextField
        Disp1.SelectionStart = B4XPages.MainPage.searchString.Length
           #Else If B4J
            Dim Disp1 As TextField = B4XFTxtSearch.TextField
            Disp1.SetSelection(Disp1.Text.Length,Disp1.Text.Length)
        #Else If B4I
            Dim Disp1 As TextField = B4XFTxtSearch.TextField
            Disp1.SetSelection(Disp1.Text.Length,Disp1.Text.Length)
        #End If

    Else
        Dim rs As ResultSet = Main.sql1.ExecQuery2("SELECT * FROM VehicleMakes WHERE MakeID = ?",Array As String(Main.currentMakeID))
        Do While rs.NextRow
            currentMakeName = rs.GetString("MakeName")
            B4XPages.SetTitle(Me,currentMakeName)
        Loop
        rs.Close
        Wait For (loadVehicles(clvModels, $"SELECT * FROM Vehicles WHERE MakeID = ? order by Model"$, Main.currentMakeID)) Complete (Success As Boolean)
    End If
    Return True
End Sub

Sub B4XPage_Disappear
    B4XPages.MainPage.searchString = ""
    B4XPages.MainPage.B4XFTxtSearch.Text = ""
End Sub

'You can see the list of page related events in the B4XPagesManager object. The event name is B4XPage.
#if b4j
Private Sub ivAddVehicle_MouseClicked (EventData As MouseEvent)
#Else
Private Sub ivAddVehicle_Click
#End If
    B4XPages.ShowPage("Add Vehicle Page")
End Sub

Sub loadVehicles(clv As CustomListView, query As String, data As String) As ResumableSub
    Dim carlist As List
'    Dim addVehicle As Boolean = False
    clv.Clear
    carlist.Initialize
    Dim cmrs As ResultSet = Main.sql1.ExecQuery2(query,Array As String(data))
    If clv = clvAKAModels Then
        clvIsAKA = True
    Else
        clvIsAKA = False
    End If
    Do While cmrs.NextRow
'        addVehicle = False
'        If Main.currentMakeID > -1 Then
'            If cmrs.GetInt("MakeID") = Main.currentMakeID Then
'                addVehicle = True
'            End If
'        Else
'            addVehicle = True
'        End If
'        If addVehicle Then
            Dim c As carSearch
            c.CMake = currentMakeName
            c.CModel = cmrs.GetString("Model")
            c.CID = cmrs.GetInt("VehicleID")
            c.CFrom = cmrs.GetInt("From")
            c.CKey = Routines.getCarKeyblank(cmrs.GetInt("VehicleID"))
            c.CChip = Routines.getChip(cmrs.GetString("Transponder"))
            If haveToolKeyway.IndexOf(cmrs.GetString("KeyblankID")) > -1 Or haveToolKeyway.IndexOf(cmrs.GetString("addKeyblankID")) > -1 Then
                c.CTool=True
            Else
                c.CTool=False
            End If
            'Log(c.CMake & ", " & c.CModel & ", " & c.CID)
            carlist.Add(c)
            clv.Add(CreateListItem2(c,clv.AsView.Width,70dip),c.CID)
'        End If
        
    Loop
    cmrs.Close
    '----- if clvAKA and have some results then display clvaka -----
    
'    If clvAKAModels.Size > 0 Then
'        clvModels.AsView.Height = (GetDeviceLayoutValues.Height - (B4XFTxtSearch.mBase.Top+B4XFTxtSearch.mBase.Height)) / 2
'        lblAKA.Top = clvModels.AsView.Top + clvModels.AsView.Height + 5dip
'        clvAKAModels.AsView.Top = lblAKA.Top + lblAKA.Height
'        clvAKAModels.AsView.Height = Root.Height - (lblAKA.Top + lblAKA.Height)
'        clvAKAModels.AsView.Visible = True
'        lblAKA.Text = "Vehicles also known as - " & B4XFTxtSearch.Text
'        lblAKA.Visible=True
'    Else
'        lblAKA.Visible=False
'        If clvAKAModels.IsInitialized Then
'            clvAKAModels.AsView.Visible=False
'        End If
'        clvModels.AsView.Height = (GetDeviceLayoutValues.Height - (B4XFTxtSearch.mBase.Top + B4XFTxtSearch.mBase.Height))
'    End If
    If clv.Size > 0 Then clv.ScrollToItem(0)
    Return True
End Sub

Sub CreateListItem2(c As carSearch, Width As Int, Height As Int) As B4XView
    Dim p As B4XView = xui.CreatePanel("")
    p.SetLayoutAnimated(0, 0, 0, Width, Height)
    p.LoadLayout("modelRowLayout")
    If clvIsAKA Then
        p.Color = xui.Color_ARGB(255,245,222,179)
        schLblChip.Color = p.Color' xui.Color_LightGray
        schLblKeyway.Color = p.Color'xui.Color_LightGray
        'lblAKA.Color = p.Color
    End If
    'schLblMake.Text = c.CMake
    schLblModel.Text = c.CModel
    schLblKeyway.Text = c.CKey
    schLblChip.Text = c.CChip
    'If c.CKey.Length < 1 Then schLblKeyway.Visible=False', schLblKeyway.Visible=True)
    'If c.CChip.Length < 1 Then schLblChip.Visible=False', schLblChip.Visible = True)
    'schLblModel.Height = su.MeasureMultilineTextHeight(schLblModel, schLblModel.Text)
    If c.CTool=True Then
        ivHaveLishi.SetBitmap(bg)
    Else
        'ivHaveLishi.Visible=False
        ivHaveLishi.SetBitmap(Null)
    End If
    'Height = schLblModel.Height
    p.Height = Height
    Return p
End Sub

Private Sub B4XFTxtSearch_TextChanged (Old As String, New As String)
    If New.Length>2 Then
        Wait For (loadVehicles(clvModels,$"SELECT * FROM Vehicles WHERE Model LIKE ? order by Model"$,$"%${New}%"$)) Complete (Success As Boolean)
        Wait For (loadVehicles(clvAKAModels,$"SELECT * FROM Vehicles WHERE AKA LIKE ? order by Model"$,$"%${New}%"$)) Complete (Success As Boolean)
        B4XFTxtSearch.RequestFocusAndShowKeyboard
        B4XFTxtSearch.TextField.SetSelection(B4XFTxtSearch.Text.Length, 0)
    End If
'    If New.Length = 0 Then
'        If Main.currentMakeID = -1 Then
'            B4XPages.ClosePage(Me)
'        Else
'            B4XFTxtSearch.Text = ""
'            clvAKAModels.Clear
'            Wait For (loadVehicles(clvModels, $"SELECT * FROM Vehicles WHERE MakeID = ? order by Model"$, Main.currentMakeID)) Complete (Success As Boolean)
'        End If
'    End If
    
End Sub


Private Sub clvModels_ItemClick (Index As Int, Value As Object)
    Main.currentVehicleID = Value
    Dim rs As ResultSet = Main.sql1.ExecQuery2($"SELECT * FROM Vehicles where VehicleID = ?"$, Array As String(Value))
    Do While rs.NextRow
        Main.currentModel = rs.GetString("Model")
        Main.currentMakeID = rs.GetString("MakeID")
        Dim rsMake As ResultSet = Main.sql1.ExecQuery2($"SELECT * FROM VehicleMakes WHERE MakeID = ?"$, Array As String (Main.currentMakeID))
        Do While rsMake.NextRow
            Main.currentMake = rsMake.GetString("MakeName")
        Loop
        rsMake.Close
    Loop
    rs.Close
    B4XPages.ShowPage("Car page")
    B4XPages.SetTitle(B4XPages.MainPage.carPage,Main.currentMake & " " & Main.currentModel)
    B4XPages.MainPage.carPage.loadFeedback("getInfoFeedback", "info")
End Sub
 
Upvote 0
Top