B4J Question [SOLVED] OnTouchListener event

Discussion in 'B4J Questions' started by Star-Dust, Apr 27, 2018.

  1. Star-Dust

    Star-Dust Expert Licensed User

    I created a class that changes the event View as a parameter by changing the view. This works well in B4A but does not work in B4J.
    This is the code:
    Code:
    Sub Class_Globals
        
    Private CallBack As Object 'ignore
        Private EventName As String 'ignore
    End Sub

    'Initializes the object. You can add parameters to this method if needed.
    Public Sub Initialize(mCallBack As Object, mEventName As String)
        CallBack=mCallBack
        EventName=mEventName
    End Sub

    Public Sub ChangeTouchEvent(View As B4XView)
       
        
    #IF B4A
           
    Dim obj As Reflector
           obj.Target=
    View
           obj.SetOnTouchListener(
    "ViewA_Touch")
        
    #ELSE IF B4J
            
    Dim jo As JavaObject = View
            
    Dim e As Object = jo.CreateEvent("android.view.View.OnTouchListener""ViewJ"False)
            jo.RunMethod(
    "setOnTouchListener"Array As Object(e))
           
        
    #ELSE IF B4i
       
        
    #End If
    End Sub
    Find the error :p .. Can anyone tell me why it does not work?

     
  2. udg

    udg Expert Licensed User

    B4J that refers an Android class?
     
    nobbi59 likes this.
  3. Star-Dust

    Star-Dust Expert Licensed User

    I copied Erel's example
     
  4. JanPRO

    JanPRO Well-Known Member Licensed User

    Hi,

    like udg already pointed out, the code for B4J is wrong and should be:

    Code:
    Dim jo As JavaObject = View
        
    Dim e As Object = jo.CreateEvent("javafx.event.EventHandler""ViewJ"False)
        jo.RunMethod(
    "setOnTouchMoved"Array(e)) 'change the event to fit your purpose
    Have a look at the Java documentation for a list of all events.

    Jan
     
  5. Star-Dust

    Star-Dust Expert Licensed User

    Thank's SOLVED
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice