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

Waldemar Lima

Well-Known Member
Licensed User
Longtime User
hello everyone !!

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

doubt.png
 

mangojack

Expert
Licensed User
Longtime User
B4X:
'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:
Upvote 0

mangojack

Expert
Licensed User
Longtime 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.

B4X:
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
 
Upvote 0
Top