B4J Question about jReflection

Gianni M

Well-Known Member
Licensed User
Longtime User
B4X:
'
Dim TextField1 as TextField
Dim TextField2 as TextField
Dim TableView1 As TableView
'
ref (TextField1)
ref (TextField2)
ref (TableView1)
'
'
'
'
Private Sub ref (t As Object)
    Dim r As Reflector
    r.Target = t
    r.AddEventHandler("keypressed", "javafx.scene.input.KeyEvent.KEY_PRESSED")
End Sub
'
Private Sub keypressed_event (e As Event)
    Log("How to know the object? ")
    Dim tt As Object = Sender
    Log(GetType(tt)) 'is that correct?
    '
    Dim KE As Reflector
    KE.Target = e
    Dim KeyCode As String
    KeyCode = KE.RunMethod("getCode")
    Log(KeyCode)
End Sub
 

teddybear

Well-Known Member
Licensed User
Log("How to know the object? ")
Add a Tag for each view, and then you can know what the object is.
B4X:
Dim TextField1 as TextField
TextField1.Tag="TF1"
ref (TextField1)
...
Private Sub keypressed_event (e As Event)
    Log("How to know the object? ")
    Dim tt As B4XView = Sender
    Log(tt.Tag) 'This is correct
    '...
End Sub
 
Last edited:
Upvote 1

Gianni M

Well-Known Member
Licensed User
Longtime User
B4X:
Private Sub keypressed_event (e As Event)
    Log("How to know the object? ")
    Dim tt As B4XView = Sender
    Log(tt.Tag) 'This is correct
    '...
End Sub
is there no other solution?
 
Upvote 0

Gianni M

Well-Known Member
Licensed User
Longtime User
Didn't it work?
it is ok!
i use .Tag, in most my app.
with a new app, i set a tag: param1, param2, param3, ...., .....
and after
B4X:
Dim param() As String = Regex.Split(",", tt.Tag)
Log(param.Length)
ok; I was wondering if a different solution was possible; thanks for your help
 
Upvote 0

Daestrum

Expert
Licensed User
Longtime User
You could use the ID field of most nodes, but it takes a bit more code to set and use
B4X:
Dim TextField1 as TextField
...
TextField1.as(JavaObject).RunMethod("setId",array("TextField1")) ' needed for each control you want

...

Private Sub keypressed_event (e As Event)
    Log("How to know the object? ")
    Dim tt As JavaObject = Sender
    Log(tt.RunMethod("getId",null)) 
    '...
End Sub
 
Upvote 0

Star-Dust

Expert
Licensed User
Longtime User
it is ok!
i use .Tag, in most my app.
with a new app, i set a tag: param1, param2, param3, ...., .....
and after
B4X:
Dim param() As String = Regex.Split(",", tt.Tag)
Log(param.Length)
ok; I was wondering if a different solution was possible; thanks for your help
store a map variable in the tag
 
Upvote 0

stevel05

Expert
Licensed User
Longtime User
You could compare the sender object to the views you are expecting:

B4X:
If sender = view1 Then
...
End If
 
Upvote 0
Top