Java Question Handle return value with RaisEvent

XverhelstX

Well-Known Member
Licensed User
Longtime User
Hi

How is it possible to return an event from a raisevent from an external activity.

For example in Basic4Android we have this:

B4X:
Sub Activity_KeyPress (KeyCode As Int) As Boolean 'Return True to consume the event
   If Keycode = KeyCodes.KEYCODE_BACK Then
      Return False
   Else
      Return False
   End If   
End Sub

In java:

B4X:
@Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
      return false;
      
   }

How is it possible to let the user choose to return false or true when an event is raised to a b4a sub

Regards,
Tomas
 
Last edited:

Informatix

Expert
Licensed User
Longtime User
How is it possible to let the user choose to return false or true when an event is raised to a b4a sub

raiseEvent and raiseEvent2 return an object by default. If you want to return a boolean, you just have to typecast the returned object.
Example:
B4X:
boolean YesNo = (boolean) m_Grid.m_BA.raiseEvent2(this, false, m_Grid.m_EventPrefix + "_question", true, new Object[] { this.X, this.Y });
 

XverhelstX

Well-Known Member
Licensed User
Longtime User
raiseEvent and raiseEvent2 return an object by default. If you want to return a boolean, you just have to typecast the returned object.
Example:
B4X:
boolean YesNo = (boolean) m_Grid.m_BA.raiseEvent2(this, false, m_Grid.m_EventPrefix + "_question", true, new Object[] { this.X, this.Y });

Great and thanks!
 
Top