Android Question No Button_Click in Custom List View

floatingpoint

Member
Licensed User
Longtime User
Probably a very simple explanation, but I cant get any Button_Click events when a button is pressed on the Custom List View.

I get ItemClick events so not sure why button is ignored (button does change color on press)

Code: Copy
Sub Button_Click
    Dim index As Int
    Dim pnl As Panel
    Dim btn As Button

    index = clvPlayers.GetItemFromView(Sender)
    pnl = clvPlayers.GetPanel(index)
    btn = pnl.GetView(1)
   
    Log("Test1 " & index)

    If OffOnGoalie(index) = 1 Then
        OffOnGoalie(index) = 0    ' If ON then OFF
        btn.Text = "OFF"
    Else If OffOnGoalie(index) = 0 Then
        OffOnGoalie(index) = 1    ' If OFF then ON
        btn.Text = "ON"
    End If
End Sub

Sub clvPlayers_ItemClick(Index As Int, value As Object)    ' Click on list centre label selects this player as the goalie
    Dim pnl1 As Panel
    Dim pnl2 As Panel
    Dim btn1 As Button
   
    Log("Test2 " & Index)

    Dim num As Int
    num = Index + 1
    Dim val As Int
    val = Msgbox2("Player " & num & " New Goalie?", "Bombers", "Yes", "Cancel", "", Null)
    If val = DialogResponse.POSITIVE Then
        For i = 0 To NumberofPlayers - 1
            If OffOnGoalie(i) = 2 Then    ' Clear any goalies currently registered
                OffOnGoalie(i) = 0
                pnl2 = clvPlayers.GetPanel(i)
           
                btn1 = pnl2.GetView(1)    ' 3rd view is button
                btn1.Text = "OFF"        ' This Goalie taken OFF
            End If
        Next
           
        pnl1 = clvPlayers.GetPanel(Index)
        OffOnGoalie(Index) = 2    ' Set new goalie
        btn1 = pnl1.GetView(1)    ' 3rd view is button
        btn1.Text = "GOALIE"    ' New Goalie put ON

        Log(Index & " = " & value)
    End If
End Sub

All suggestions appreciated.

FP
 
Unfortunately you don't give enough information.
How do you initialize the buttons when you create an item ?
Did you set the EventName to "Button" ?
How many views do you have in an item and what index does the button have ?

Thank you both for replies.

Yes a simple answer!

Code: Copy
Sub CreateListItem(Text As String, Width As Int, Height As Int) As Panel
    Dim p As Panel
    p.Initialize("")
    p.Color = Colors.Black
    Dim b As Button
    b.Initialize("") 'all buttons click events will be handled with Sub Button_Click

Should be


Sub CreateListItem(Text As String, Width As Int, Height As Int) As Panel
    Dim p As Panel
    p.Initialize("")
    p.Color = Colors.Black
    Dim b As Button
    b.Initialize("button") 'all buttons click events will be handled with Sub Button_Click

I didn't realize that the ("button") parameter was the button EventName.

Thank you, working well.

FP
 
Upvote 0
Code: Copy
Sub CreateListItem(Text As String, Width As Int, Height As Int) As Panel
    Dim p As Panel
    p.Initialize("")
    p.Color = Colors.Black
    Dim b As Button
    b.Initialize("Button") 'all buttons click events will be handled with Sub Button_Click
 
Upvote 0
Code: Copy
Sub CreateListItem(Text As String, Width As Int, Height As Int) As Panel
    Dim p As Panel
    p.Initialize("")
    p.Color = Colors.Black
    Dim b As Button
    b.Initialize("Button") 'all buttons click events will be handled with Sub Button_Click

Yes, my 'C' programming brain told me that ("button") had no association with Sub Button_Click because of different case.

Is the use of mixed case just sloppy programming or is there a convention in Basic regarding parameters and event calls?
 
Upvote 0
and it's better to let the editor guide you when creating these click events, otherwise quite often it doesn't recognise them.
 
Upvote 0
Back
Top