B4J Question [ clvExpandable ] how can i get Item # Value ?

Discussion in 'B4J Questions' started by Waldemar Lima, Nov 9, 2019.

  1. Waldemar Lima

    Waldemar Lima Active Member Licensed User

    hello everyone !!

    how can i get a text from lblTitle or other items from clv ?

    doubt.png
     
  2. mangojack

    mangojack Well-Known Member Licensed User

    Code:
    'Title Panel ...
    Dim pnlTitle As B4XView = clv1.GetPanel(Index).GetView(0'pnlTitle is First Item on Item layout
    pnlTitle.GetView(0).Text = "This is a New Title"   'lblTitle is first pnlTitle View
     
    'Items Panel ...
    Dim pnlItems As B4XView = clv1.GetPanel(Index).GetView(1'pnlExpanded is Second Item on Item layout
    pnlItems.GetView(0).Text = "ABC"      '1st panel view
    pnlItems.GetView(1).Text = "123"     '2nd panel view
    Edit ... Just realized ...

    The above code works with this example (using xCustomListView class)
    https://www.b4x.com/android/forum/attachments/b4j_expandablelist-zip.61998/

    but does not work with the recommended clvExpandable class ..
    https://www.b4x.com/android/forum/t...g-or-collapsing-xcustomlistview-items.106148/.

    Have a bit of time to kill so will have a look.
     
    Last edited: Nov 10, 2019
    Waldemar Lima likes this.
  3. mangojack

    mangojack Well-Known Member Licensed User

    The above code does work as is with with the CLVExpandable class ...
    https://www.b4x.com/android/forum/t...g-or-collapsing-xcustomlistview-items.106148/


    The problem was i was testing it in a CLV_Click event sub which would cause an error ...
    java.lang.IndexOutOfBoundsException: Index: 0, Size: 0

    Adding a Sleep(400) solved this error.

    Code:
    Sub clv1_ItemClick (Index As Int, Value As Object)
        expandable.ToggleItem(Index)
     
        Sleep(
    400)  ' stops error

        
    'Title Panel ...
        Dim pnlTitle As B4XView = clv1.GetPanel(Index).GetView(0)   'pnlTitle is First Item on Item layout
        pnlTitle.GetView(0).Text = "This is a New Title"            'lblTitle is first pnlTitle View

        
    'Items Panel ...
        Dim pnlItems As B4XView = clv1.GetPanel(Index).GetView(1)   'pnlExpanded is Second Item on Item layout
        pnlItems.GetView(0).Text = "ABC"      '1st panel view
        pnlItems.GetView(1).Text = "123"      '2nd panel view

    End Sub


    'the same code in a View_Click sub does not require a Sleep() line.

    Sub Button2_Click
     
        
    'no sleep required
        Dim index As Int = clv1.GetItemFromView(Sender)
     
        
    'Title Panel ...
        Dim pnlTitle As B4XView = clv1.GetPanel(index).GetView(0)   'pnlTitle is First Item on Item layout
        pnlTitle.GetView(0).Text = "This is another new Title !"    'lblTitle is first pnlTitle View

        
    'Items Panel ...
        Dim pnlItems As B4XView = clv1.GetPanel(index).GetView(1)   'pnlExpanded is Second Item on Item layout
        pnlItems.GetView(0).Text = "DEF"      '1st panel view
        pnlItems.GetView(1).Text = "456"      '2nd panel view
     
    End Sub
     
    Waldemar Lima likes this.
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