Android Question Custome ListView

Discussion in 'Android Questions' started by Kiran Raotole, Jul 16, 2018.

  1. Kiran Raotole

    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.
     
  2. Alexander Stolte

    Alexander Stolte Well-Known Member Licensed User

    ERROR 101 Question not found.

    What is the Question?
    whether it is possible?
    How to do it?

    More Infos please. And yes it is possible.:):)
     
  3. Kiran Raotole

    Kiran Raotole Active Member Licensed User

    I want to create listview of textview more than one having different color and sizes.
    I dont know how to do that.

    I'm new in B4A.
     
  4. Alexander Stolte

    Alexander Stolte Well-Known Member Licensed 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:
    Code:
    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. ;):)
     
  5. Kiran Raotole

    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.
     
  6. Peter Simpson

    Peter Simpson Expert Licensed 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: Jul 16, 2018
  7. Kiran Raotole

    Kiran Raotole Active Member Licensed User

    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
     
  8. Alexander Stolte

    Alexander Stolte Well-Known Member Licensed User

    Please use
    Code:
    code here...
    tags when posting code.
     
  9. Kiran Raotole

    Kiran Raotole Active Member Licensed User

    Code:
    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
     
  10. Peter Simpson

    Peter Simpson Expert Licensed User

    Hmm, the following takes about 7 seconds on my device in release mode.

    Code:
    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...
     
    Erel likes this.
  11. Alexander Stolte

    Alexander Stolte Well-Known Member Licensed User

    I think this is the problem. He certainly tested this in debug mode.
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice