Android Question CustomListView: how to get/add?


Licensed User
In CustomListView, I want to modify a panel whenever a user clicks on it. However, the simple operation of getting a panel and adding it to the back of the CustomListView is crashing, much less anything fancy.
What am I doing wrong?

Sub clv_ItemClick (Index AsInt, Value AsObject)
Dim pnl AsPanel
pnl = clv.GetPanel(Index)
clv.Add(pnl, mypanel_size_dip,"try but crashes here")
End Sub

My next question will be; once I get this panel, how do I get its contents, such as an ImageView or text?




Well-Known Member
Licensed User
What error message do you get?

With regard to getting the contents of the panel, you can easily get each view contained in the panel. I do this with the following code which basically highlights items in the list when selected or deselects then if already highlighted...
Public Sub clvItem_Selection(index As Int, selected As Boolean)
    ' Set background colour (called by Music Module, only applies to audio tracks)
    Dim colorBackground As Int
    If selected = True Then
        ' Selected colour
        colorBackground = Colors.LightGray
        ' De-selected colour
        colorBackground = Colors.DarkGray
    End If
    ' Check that index is within bounds of the CustomListView then apply background colour (select or de-select)
    If clv.GetSize > index Then
        ' Get parent panel
        Dim pItem As Panel
        pItem = clv.GetPanel(index)
        For Each v As View In pItem
            ' Set label colour
            If v Is Label Then
                v.Color = colorBackground
            End If
        ' Set panel colour
        pItem.Color = colorBackground
    End If
End Sub
Hope it helps,