Android Question CustomListView and Android 16

menneaduplo

Member
Licensed User
Longtime User
I wanted to use the CustomListView in my project instead of the standard ListView.

I had no problems until I ran the project on a recent tablet and an Android 16 smartphone.

Unfortunately, execution on these devices is very slow (they are very recent devices).

The same project runs fine on smartphones and tablets over 6 years old on Android 10, 11, and 12.

The same phenomenon is also seen with the sample apps on the blog.

I also tried eliminating the animation times, but without any noticeable results.

Do you know of any tricks to solve the problem?
Thanks in advance.
 

zed

Well-Known Member
Licensed User
The solution is to adapt your code with lazy loading and the latest version of xCLV.
You don't need to rewrite everything, but limit the number of items loaded simultaneously and optimize your layouts.
 
Upvote 0

menneaduplo

Member
Licensed User
Longtime User
Thanks for the quick response.
I'm already using the latest version of xCLV.
It loads very quickly (I only have 90 items, and the layout is very simple: 1 label, 2 edittext, and 1 button).
The only problem is when scrolling up and down the list.
The strange thing is that on older Androids, everything is very fast.
On Android 16, however, there's a problematic slowness.
It's certainly due to the operating system, but if I don't find a solution, I'll have to abandon CustomListView.
Thanks
 
Upvote 0

Brian Dean

Well-Known Member
Licensed User
Longtime User
I had no problems until I ran the project on a recent tablet and an Android 16 smartphone.

All that I can say is that CLV runs perfectly normally on my Android 16 phone. Here is a small demo that I wrote recently to answer another forum question. It is ultra-simple, but try the "Long List" option - that creates a list of 99 items.

If that does not help you solve your problem then post some code. The problem is much more likely to be in your code than in the CLV component, otherwise the forum would be full of questions!
 

Attachments

  • CLVDemo.zip
    11.1 KB · Views: 3
Upvote 0

menneaduplo

Member
Licensed User
Longtime User
All that I can say is that CLV runs perfectly normally on my Android 16 phone. Here is a small demo that I wrote recently to answer another forum question. It is ultra-simple, but try the "Long List" option - that creates a list of 99 items.

If that does not help you solve your problem then post some code. The problem is much more likely to be in your code than in the CLV component, otherwise the forum would be full of questions!
Thanks for your example.
Your example actually works fast even on Android 16 machines.
Now I'll have to figure out what's causing the problem.
I'm attaching my example project anyway.
Maybe I should look into the item's layout.
Thanks.
 

Attachments

  • CustomListView.zip
    14.3 KB · Views: 6
Upvote 0

menneaduplo

Member
Licensed User
Longtime User
The cause seems to be the edit text. Reducing the number of edit texts in the element layout significantly increases performance. The number of labels, however, doesn't seem to cause any problems.
It's a shame because I needed at least 6 edit texts.
Thanks anyway
 
Upvote 0

Brian Dean

Well-Known Member
Licensed User
Longtime User
Reducing the number of edit texts in the element layout significantly increases performance.
I have tried your example and I see your problem. I don't know what the cause is but I don't think that it is simply the number of edit boxes. I will give this some more thought.

I am posting this rather unhelpful reply to encourage other forum users to download your example and suggest some better solution.

Edit : But if it turns out that the number of edit boxes is the problem then lazy-loading is the obvious solution as @zed mentioned earlier.
 
Last edited:
Upvote 0

zed

Well-Known Member
Licensed User
Your code has been corrected with Lazy Loading.
Works perfectly.

PCLV:
Sub Globals
    'These global variables will be redeclared each time the activity is created.
    Private Clv1 As CustomListView
    Private Label1 As Label
    Private PCLV As PreoptimizedCLV
End Sub

Sub Activity_Create(FirstTime As Boolean)
    Activity.LoadLayout("Main")
  
    ' Initializing PCLV with your CustomListView
    PCLV.Initialize(Me, "PCLV", Clv1)

  
    For i = 0 To 200   'Increased to 200
        'We're not creating the panel here, we're just adding a virtual item
        PCLV.AddItem(140dip, xui.Color_White, "Item description " & i)
    Next

    ' Validation
    PCLV.Commit
End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

Sub Button1_Click
    MsgboxAsync("Hello world!", "B4X")
End Sub

' Managing the rendering of visible items
Private Sub Clv1_VisibleRangeChanged (FirstIndex As Int, LastIndex As Int)
    For Each i As Int In PCLV.VisibleRangeChanged(FirstIndex, LastIndex)
        Dim item As CLVItem = Clv1.GetRawListItem(i)
        Dim pnl As B4XView = xui.CreatePanel("")
        item.Panel.AddView(pnl, 0, 0, item.Panel.Width, item.Panel.Height)
        'Load your item layout
        pnl.LoadLayout("main_item")
        Label1.Text = item.Value
    Next
End Sub


'Click on an item
Private Sub Clv1_ItemClick (Index As Int, Value As Object)
    Log("Item " & Index & " clicked, value=" & Value)
End Sub

' Click on a button in the item
Private Sub BtnItem_Click
    Dim Index As Int = Clv1.GetItemFromView(Sender)
    Log("Button in item " & Index & " clicked")
End Sub
 
Upvote 0
Top