Android Question Reflector x Spinner

Bob Spielen

Active Member
Licensed User
Need some help...
How can I "listen" with a Reflector to a Spinner ItemClick.
Im trying to catch a spinner.SelectedItem of a spinner placed on a panel in a listView.
Is it possible to use r.setOnItemClickListener instead of r.SetOnClickListener("Test1")?
Thanks a lot in advance.
 
Last edited:

Bob Spielen

Active Member
Licensed User
Mr. Erel, Thanks a lot for your, as allways, fast reply.
I based my solution on Informatix's Class module CheckList v2.22. Worked fine with Button, but with Spinner I got stucked.

B4X:
Sub CriaPnl(h As Int, w As Int, T As String, T1 As String, tipo As Int, PanX As Panel) As Panel
    Dim pnl As Panel, lbl As Label, lbl1 As Label
    PanX.Initialize("PanX")
    lbl.initialize("lbl")
    lbl1.initialize("lbl1")
    btn1.initialize("btn1")
 
    'pnl.Color=Colors.Blue
    '==============================================================================================================
    lbl.Text=T
    lbl.TextSize = 16
    lbl.TextColor = Colors.White
    lbl.Visible=True
    lbl.Gravity = Gravity.CENTER_VERTICAL
    PanX.AddView(lbl,5dip, 0, 200dip, h)
    '==============================================================================================================
    Select tipo
        Case 1    '==============================================================================================================
            lbl1.Text=T1
            lbl1.TextSize=16
            lbl1.TextColor=Colors.White
            lbl1.Gravity = Gravity.CENTER_VERTICAL
            PanX.AddView( lbl1, 200dip, 0, 80dip, h)
                 
        Case 2    '======================================== Forma de Pgto ======================================================================
            spinn.TextSize=16
            spinn.TextColor=Colors.White
            spinn.AddAll(Array As String("Dinheiro", "C.Débito", "C.Credito", "Vale"))
            spinn.Color=Colors.Red
            spinn.DropdownBackgroundColor=Colors.red
            PanX.AddView( spinn, 190dip, 0, 120dip, h-10)
            spinn.Padding = Array As Int (2dip, 0dip, 0dip, 0dip)
            spinn.Height=30dip
        Case 3    '======================================== Forma de Entrega   ======================================================================
            spinn1.TextSize=16
            spinn1.TextColor=Colors.White
            spinn1.AddAll(Array As String("Retira", "Delivery"))
            spinn1.Color=Colors.red
            spinn1.DropdownBackgroundColor=Colors.red
            PanX.AddView( spinn1, 190dip, 0, 120dip, h-10)
            spinn1.Padding = Array As Int (2dip, 0dip, 0dip, 0dip)
            spinn1.Height=30dip
            Dim r As Reflector
            r.Target = spinn1
            'r.SetOnClickListener("Teste")
            ' You probably want setOnItemClickListener instead
            'r.SetOnKeyListener("Teste1")
         
        Case 4 '======================================== Botão OK!   ======================================================================
            btn1.TextSize=16
            btn1.TextColor=Colors.White
            btn1.Color=Colors.Magenta
            btn1.Padding = Array As Int (2dip, 3dip, 0dip, 0dip)
            btn1.Text="Ok!"
            PanX.AddView(btn1, 190dip, 0, 120dip, h)
         
            Dim r As Reflector
            r.Target = btn1
            'r.SetOnTouchListener("OkBTN_Touch")
            'If sub_Click <> "" Then r.SetOnClickListener("pnlSV_Click")
            r.SetOnClickListener("OkBTN_Click")
            'If sub_LongClick <> "" Then r.SetOnLongClickListener("pnlSV_LongClick") Then r.SetOnClickListener("pnlSV_Click")
         
    End Select

    Return PanX
End Sub
'

I use also a TabStrip as "Menu", with ScrollViews in the layouts.

Until now , I never used CustomListView. But if you suggest as a better approach I will try it. Still have to learn a lot.
Would then kindly ask you for a link with an example.
Thanks in advance.
 
Last edited:
Upvote 0

Bob Spielen

Active Member
Licensed User
Following your suggestion I began to study CustomListView (The class, not the lib) and came up with the idea:


B4X:
            '.
            '.
            Dim r As Reflector
            r.Target = spinn1
            r.SetOnTouchListener("Panel_Touch")
            EventName="spinn1"
            '.
            '.




Private Sub Panel_Touch (Action As Int, X As Float, Y As Float)
   If Action <> 0 Then '0 => Activity.ACTION_DOWN
      If SubExists(CallbackMod, EventName & "_ItemClick") Then
         Dim v As View
         v = Sender
         CallSub3(CallbackMod, EventName & "_ItemClick", v.Tag, items.Get(v.Tag))
      End If
   End If
End Sub

How can I get the items list mentioned in CallSub3(CallbackMod, EventName & "_ItemClick", v.Tag, items.Get(v.Tag)) ?

Would this be a solution? For now?
 
Last edited:
Upvote 0
Top