iOS Question CLV works differently in ios

red30

Well-Known Member
Licensed User
Longtime User
I just started working with ios and got to CustomListView and realized that this element behaves quite differently from Android. Here I have collected all the differences I found from Android.
B4X:
Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'Public variables can be accessed from all modules.
    Public App As Application
    Public NavControl As NavigationController
    Private Page1 As Page
    Private xui As XUI
    Private clv As CustomListView
    Private lblTitle As Label
    Private tv As TextView
End Sub

Private Sub Application_Start (Nav As NavigationController)
    NavControl = Nav
    Page1.Initialize("Page1")
    Page1.RootPanel.LoadLayout("Page1")
    NavControl.ShowPage(Page1)
    
    Sleep(100)'if not add CLV is not displayed
    For i=0 To 15
        clv.Add(CreateOkNotOk("Item "&i),"")
    Next
    
    Sleep(100)'if you don't add CLV, the width of the first element will not be excused
    Dim pnl As B4XView = clv.GetPanel(0)
    Dim lbl As B4XView = pnl.GetView(0)
    lbl.Width=Page1.RootPanel.Width*0.30 'and here it works
End Sub


Private Sub Page1_Resize(Width As Int, Height As Int)
    
End Sub

Sub CreateOkNotOk(Text As String) As Panel
    Dim p As B4XView = xui.CreatePanel("")
    p.SetLayoutAnimated(0, 0, 0, clv.AsView.Width, Page1.RootPanel.Height*0.25)
    p.LoadLayout("Page2")
    lblTitle.Text=Text
    tv.Color=Colors.White
    If Text="Item 0" Then
        lblTitle.Width=Page1.RootPanel.Width*0.30 'doesn't work here
    End If
    Return p
End Sub

Sub lblOk_Click
    Dim index As Int = clv.GetItemFromView(Sender)
    clv.ResizeItem(index,Page1.RootPanel.Height*0.09) 'as soon as the sub ends the CLV element is redrawn
End Sub

Sub lblNot_Click
    Dim index As Int = clv.GetItemFromView(Sender)
    clv.ResizeItem(index,Page1.RootPanel.Height*0.25)
End Sub

Private Sub clv_ScrollChanged (Offset As Int)
    Page1.ResignFocus
End Sub
Using this program as an example, I would like to know:
1) If you do not put "Sleep (100)" before displaying the CLV list, then CLV simply will not be displayed. Why?
2) When I create a CLV element, I would like to change the width of "lblTitle" in the zero element, but I cannot do this in "CreateOkNotOk". I can do this only after displaying the entire list and only if I put "Sleep (100)" before it again. Why?
B4X:
    Sleep(100)
    Dim pnl As B4XView = clv.GetPanel(0)
    Dim lbl As B4XView = pnl.GetView(0)
    lbl.Width=Page1.RootPanel.Width*0.30
3) If I try to change the height of the CLV element, for example to hide the "TextView". If I look in debug, then after the line "clv.ResizeItem (index, Page1.RootPanel.Height * 0.09)" the height changes as I want
IMG_0011.PNG
but after the sub ends, I get this result
IMG_0012.PNG
Why?
4) When the keyboard appears in the last element, it closes the element itself. How can this be fixed? On Android I used the IME library for this
the code
B4X:
Sub IME_HeightChanged(NewHeight As Int, OldHeight As Int)
    clv.Base_Resize(100%x,NewHeight-Activity.Height*0.18)
End Sub
P.S. I also attach the program code
 

Attachments

  • testCLVios.zip
    62.9 KB · Views: 160

Erel

B4X founder
Staff member
Licensed User
Longtime User
1. All the conclusions are not related to CLV. They are related to the way the page is resized.

The simple solution is to do everything with the designer. Things will simply work as you expect.
Otherwise you need to handle the resize event and resize the views when the page is resized.

It is explained in the B4J / B4i Resize event video tutorial: https://www.b4x.com/etp.html

2. Why aren't you using B4XPages for a new project? It will save you a lot of time.

3. You can wait for the page to be resized with this code:
B4X:
If Root.Width = 0 Then
        Wait For B4XPage_Resize (Width As Int, Height As Int)
End If
Though it will not solve all issues. Building with designer will solve.
 
Upvote 0

red30

Well-Known Member
Licensed User
Longtime User
2. Why aren't you using B4XPages for a new project? It will save you a lot of time.
I already had an application for Android. I also found using B4XPages more complicated. Each operating system has its own characteristics. I am using the B4X library and am already getting 70% compatible code.
Though it will not solve all issues. Building with designer will solve.
Yes you are right it solves all my problems, but is it correct to turn off "handle resize event"?

And the question with the keyboard, which closes part of the elements, when I call the keyboard at the bottom of the CLV, is it possible to somehow solve it?
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
I also found using B4XPages more complicated
No it is not. Take the time to learn it and you will see that it is much simpler. Especially in B4A.
I am using the B4X library and am already getting 70% compatible code.
With B4XPages you will get 95%.

but is it correct to turn off "handle resize event"?
Depends on the use case. By default you should keep it enabled.

And the question with the keyboard, which closes part of the elements, when I call the keyboard at the bottom of the CLV, is it possible to somehow solve it?
 
Upvote 0

red30

Well-Known Member
Licensed User
Longtime User
I've tried using:
B4X:
Private Sub pg_KeyboardStateChanged (Height As Float)
    Dim v As View = allclv.AsView
    allclv.GetBase.Height = Min(v.CalcRelativeKeyboardHeight(Height), pg.RootPanel.Height - 10dip - allclv.GetBase.Top)
End Sub
But I have a keyboard collapse event when scrolling CLV
B4X:
Private Sub allclv_ScrollChanged (Offset As Int)
    pg.ResignFocus
End Sub
It doesn't work the way I wanted it to. Am I doing something wrong?
I need to have the event of minimizing the keyboard when scrolling through the CLV, and also if the keyboard was called at the bottom of the CLV, then it did not close the input field.
 
Upvote 0
Top