I have a simple spinner in my app and I'd like to turn on/off a timer whenever that spinner is clicked on. That is NOT selecting an item inside, for which there is a dedicated even, but I'm interested in catching the even that occurs when the spinner shows its contents by dropdown.
I am not an expert in the use of Reflection, but I have tried to write this:
B4X:
Sub Activity_Create(FirstTime As Boolean)
'...
If FirstTime Then
Spinner1.Add("One")
Spinner1.Add("Two")
AddOnTouch(Spinner1, "Spinner1_onTouch")
End If
End Sub
Sub Spinner1_onTouch(V As Object, Action As Int, X As Float, Y As Float, MotionEvent As Object) As Boolean
Log("Spinner1_onTouch")
Return False
End Sub
Sub AddOnTouch(V As View, Event As String)
Private r As Reflector
r.Target = V
r.SetOnTouchListener(Event)
End Sub
(You should import the library Reflection)
Are you sure you do not have a more simple solution instead of using a timer, check the opening of the spinner, etc?
I tried the example above and it gave out an error saying the Spinner should be first initialized. I'm using a Spinner that's embedded in the layout that I designed with the visual designer, so as far as I know those are already initialized.
I tried the example above and it gave out an error saying the Spinner should be first initialized. I'm using a Spinner that's embedded in the layout that I designed with the visual designer, so as far as I know those are already initialized.
Any suggestions?
In this line AddOnTouch(Spinner1, "Spinner1_onTouch")
you must replace Spinner1 by the name of your spinner !
The code in the example that is in FirstTime should be out of FirstTime.
It would be easier to help if you posted your code.