Android Question Custome ListView

Kiran Raotole

Active Member
Licensed User
Hi everybody. I want to create custom listview with three different fontsize textview in each row.

Thanks in Advance.
 

Alexander Stolte

Expert
Licensed User
Longtime User
If you add a new item to the List, then you have the possibility pass parameters. These parameters can be colors, sizes, text, id's. Which parameters you want to pass, you decide.

i take this example from the xCustomListView Tutorial:
B4X:
clv2.Add(CreateListItem($"Item #${i}"$, 160dip, clv2.AsView.Height), $"Item #${i}"$)

Following: "CreateListItem" is the Function to add the new List Item.
and this: "($"Item #${i}"$, 160dip, clv2.AsView.Height)" are the parameters from this Function (CreateListItem).

The Parameters are variable.

I recommend you to read through the tutorial here and to try it, then you will notice how the CustomListView is built and works.
Erel even made a video tutorial about it.

Check it out, then your questions will be answered by yourself. ;):)
 
Upvote 0

Kiran Raotole

Active Member
Licensed User
Thanks it works.

But it takes too much time,
For i = 1 To 5000
Dim iv As ItemValue
iv.Initialize
clv1.Add(Create_Item( i , iv ), iv)
Next
for 5000 item it take 1 minute
I proccessed as shown in video.

there is any way to make it fast.
 
Upvote 0

Peter Simpson

Expert
Licensed User
Longtime User
5000 lines on my devices usually takes about 5 seconds to populate from an online database (1000 lines per second on average), but that does depend on how complicated your CLV is and if you are loading images.

Anyway, you should implement xCustomListView with lazy loading, I load 40 lines at a time for my clients and you can easily load thousands of lines with no issues whatsoever, scrolling down the list is nice and smooth too.

CLICK HERE for xCLV with lazy loading
 
Last edited:
Upvote 0

Kiran Raotole

Active Member
Licensed User
5000 lines on my devices usually takes about 5 seconds to populate from an online database, but that does depend on how complicated your CLV is and if you are loading images.

Anyway, you should implement xCustomListView with lazy loading, I load 40 lines at a time.

This is my code. I did not change anything in CLV.

Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.
Private xui As XUI
Type ItemValue (value As String)
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 clv_label1 As Label
Private clv_label2 As Label
Private clv_button1 As Button
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("main")
Log("The time now is: " & DateTime.Time(DateTime.Now))
For i = 1 To 10000
Dim iv As ItemValue
iv.Initialize
clv1.Add(Create_Item( i , iv ), iv)
Next
Log("The time now is: " & DateTime.Time(DateTime.Now))

End Sub

Private Sub Create_Item (lv1 As String,iv As ItemValue) As B4XView
Dim p As B4XView = xui.CreatePanel("")
p.SetLayoutAnimated(0,0,0,80%x,120dip)
p.LoadLayout("ItemLayout")
clv_label1.Text = lv1
clv_label2.Text = lv1
iv.value = lv1
Return p
End Sub
 
Upvote 0

Kiran Raotole

Active Member
Licensed User
B4X:
Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.
    Private xui As XUI
    Type ItemValue (value As String)
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 clv_label1 As Label
    Private clv_label2 As Label
    Private clv_button1 As Button
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("main")
    Log("The time now is: " & DateTime.Time(DateTime.Now))
    For i = 1 To 10000
        Dim iv As ItemValue
        iv.Initialize
        clv1.Add(Create_Item( i , iv ), iv)
    Next
    Log("The time now is: " & DateTime.Time(DateTime.Now))
    
End Sub

Private Sub Create_Item (lv1 As String,iv As ItemValue) As B4XView
    Dim p As B4XView = xui.CreatePanel("")
    p.SetLayoutAnimated(0,0,0,80%x,120dip)
    p.LoadLayout("ItemLayout")
    clv_label1.Text = lv1
    clv_label2.Text = lv1
    iv.value = lv1
    Return p
End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

Sub clv1_ItemClick (Index As Int, Value As Object)
    Dim iv As ItemValue = clv1.GetValue(Index)
    Log(iv.value)
    Log("Int " & Index & ", Object "& Value)
    ToastMessageShow(clv_label1.Text,False)
End Sub
 
Upvote 0

Peter Simpson

Expert
Licensed User
Longtime User
Hmm, the following takes about 7 seconds on my device in release mode.

B4X:
Sub Activity_Create(FirstTime As Boolean)
    Activity.LoadLayout("1")
    clv1.AddTextItem("4Aaaa" & CRLF & "Bbbb" & CRLF & "Cccc" & CRLF & "Dddd" & CRLF & "Eeee", "e")
    For i = 1 To 5000
        clv2.Add(CreateListItem($"Item #${i}"$, clv2.AsView.Width, 60dip), $"Item #${i}"$)
    Next
End Sub

Anyway, you should just use xCLV with lazy loading, that will cure all your issues...
 
Upvote 0
Top