Android Programming Press on the image to return to the main documentation page.

JavaObject

List of types:

JavaObject

JavaObject


Events:

Event (MethodName As String, Args() As Object) As Object

Members:


  CreateEvent (Interface As String, EventName As String, DefaultReturnValue As Object) As Object

  CreateEventFromUI (Interface As String, EventName As String, ReturnValue As Object) As Object

  GetField (Field As String) As Object

  GetFieldJO (Field As String) As JavaObject

  InitializeArray (ClassName As String, Values() As Object) As JavaObject

  InitializeContext As JavaObject

  InitializeNewInstance (ClassName As String, Params() As Object) As JavaObject

  InitializeStatic (ClassName As String) As JavaObject

  IsInitialized As Boolean

  RunMethod (MethodName As String, Params() As Object) As Object

  RunMethodJO (MethodName As String, Params() As Object) As JavaObject

  SetField (FieldName As String, Value As Object)

Members description:

CreateEvent (Interface As String, EventName As String, DefaultReturnValue As Object) As Object
Creates an instance of the interface and binds it to the object.
Interface - The full interface name.
EventName - The prefix of the event sub.
DefaultReturnValue - This value will be returned if no value was returned from the event sub. This can happen if the Activity is paused for example.

For example:
Sub Activity_Create(FirstTime As Boolean)
Dim b As Button
b.Initialize("")
Activity.AddView(b, 0, 0, 200dip, 200dip)
Dim jo As JavaObject = b
Dim e As Object = jo.CreateEvent("android.view.View.OnTouchListener", "btouch", False)
jo.RunMethod("setOnTouchListener", Array As Object(e))
End Sub

Sub btouch_Event (MethodName As String, Args() As Object) As Object
Dim motion As JavaObject = Args(1) 'args(0) is View
Dim x As Float = motion.RunMethod("getX", Null)
Dim y As Float = motion.RunMethod("getY", Null)
Log(x & ", " & y)
Return True
End Sub
CreateEventFromUI (Interface As String, EventName As String, ReturnValue As Object) As Object
Similar to CreateEvent. The event will be sent to the message queue and then be processed (similar to CallSubDelayed).
GetField (Field As String) As Object
Gets the value of the given field.
GetFieldJO (Field As String) As JavaObject
Similar to GetField. Returns a JavaObject instead of Object.
InitializeArray (ClassName As String, Values() As Object) As JavaObject
Creates an array with the given class and values.
InitializeContext As JavaObject
B4A only method.
Initializes the object with the current context (current Activity or Service).
InitializeNewInstance (ClassName As String, Params() As Object) As JavaObject
Creates a new instance of the given class.
ClassName - The full class name.
Params - An array of objects to pass to the constructor (or Null).
InitializeStatic (ClassName As String) As JavaObject
Initializes the object. The object will wrap the given class (for static access).
ClassName - The full class name.
IsInitialized As Boolean
RunMethod (MethodName As String, Params() As Object) As Object
Runs the given method and returns the method return value.
MethodName - The case-sensitive method name.
Params - Method paramters (or Null).
RunMethodJO (MethodName As String, Params() As Object) As JavaObject
Similar to RunMethod. Returns a JavaObject instead of Object.
SetField (FieldName As String, Value As Object)
Sets the value of the given field.
Top