Android Question Custom View - myTimer

Gianni Sassanelli

Active Member
Licensed User
Longtime User
Hi i need to make a myTimer that extend timer object adding some properties.

I have tried bu i have a problem. The timer_tick event fires in class module but i want to fire it in my activity module where i USE the myTymer object

i have written the following code.
the problem is in tm2_tick sub

Can help me please?
thanks

''' CLASS module
B4X:
Sub Class_Globals
    Private EventName     As String 'ignore
    Private CallBack         As Object 'ignore
    Private mBase             As Timer
    Public  Message        As String
    Public  Caption        As String
End Sub

Public Sub Initialize (vCallback As Object, vEventName As String, vInterval As Int)
    EventName             = vEventName
    CallBack             = vCallback
   
    vEventName    = "myTimer"   ' overwrited parameter for test 
    mBase.Initialize(vEventName,vInterval)
    'mBase.Initialize(vEventName,vInterval)
End Sub

'Public Sub DesignerCreateView (Base As Panel, Lbl As Label, Props As Map)
'    mBase = Base 
'End Sub

Public Sub GetBase As Timer
    Return mBase
End Sub

Sub getMessage As String
    Return Message
End Sub
Sub setMessage(P    As    String)
    Message = p
End Sub

Sub getCaption As String
    Return Caption
End Sub
Sub setColonna(P    As    String)
    Caption = p
End Sub

Sub getEnabled As Boolean
    Return mBase.Enabled
End Sub
Sub setEnabled(P    As    Boolean)
    mBase.Enabled = p
End Sub


Sub myTimer_tick
    mBase.Enabled = False
    Msgbox("Timer tick event of BaseClass","BaseClass")
End Sub


''' Activity CODE --- in tm2_Tick sub i have the problem

B4X:
#Region  Activity Attributes 
    #FullScreen: True
    #IncludeTitle: false
#End Region

Sub Process_Globals

End Sub

Sub Globals
'    These global variables will be redeclared each time the activity is created.
'    These variables can only be accessed from this module.
    Dim tm2 As tsTimer
End Sub

Sub Activity_Create(FirstTime As Boolean)
    Activity.LoadLayout("atest_lay")
    tm2.Initialize("tm2","tm2",3000)
    tm2.Enabled = False 
    tm2.Caption = "caption "
    tm2.Message = "messaggio"
    tm2.Enabled = True
End 

Sub tm2_Tick
''' in this point i need to insert my code
''  this don't fires
msgbox("subclassed timer_tick Event","SUBCLASSED")
End Sub
 

derez

Expert
Licensed User
Longtime User
You have to call the sub in the activity from the class sub myTimer_tick , like this:

B4X:
If SubExists(CallBack, eventname & "_tick") Then
    CallSub(CallBack, eventname & "_tick")
End If

It is a good habit to use CallSubDelayed but this is not suitable for a timer which needs immediate action.
 
Last edited:
Upvote 0

Gianni Sassanelli

Active Member
Licensed User
Longtime User
Hi derez
thanks for yuur help.
this solve my problem but i have modified also this line
B4X:
'' old code
'     tm2.Initialize("tm2","tm2",3000)

'NEW CODE
     tm2.Initialize(Me,"tm2",3000)

thank's for your suggestion
 
Upvote 0
Top