If I have a Sub with a parameter aObject as Object, how can I determine if the aObject that was passed is Activity or a View?
The only way to determine it is to use a Try/Catch block which isn't very clean.
Is there a better way?
I thought I could use:
But all views (panel, button etc.) that are passed will execute:
"if aObject is Activity then"
It appears all Views Is Activity and Activity is View. This does not make sense to me because if I try and reference Activity as View it throws an exception:
"java.lang.ClassCastException: android.widget.FrameLayout$LayoutParams cannot be cast to anywheresoftware.b4a.BALayout$LayoutParams"
So is there a better way to detect between a View and Activity?
TIA
The only way to determine it is to use a Try/Catch block which isn't very clean.
Is there a better way?
B4X:
public Sub GetViewDim(aObject As Object) As TRectDim
Private Result As TRectDim
If aObject Is View Then
Try
Private locView As View
locView = aObject
Result.Initialize(locView.Left, locView.Top, locView.Width, locView.Height)
Catch
Log(LastException)
Private locActivity As Activity
locActivity = aObject
Result.Initialize(locActivity.Left, locActivity.Top, locActivity.Width, locActivity.Height)
End Try
Else
If aObject Is CustomListView Then
Private locCLV As CustomListView
locCLV = aObject
Result.Initialize(locCLV.Left, locCLV.Top, locCLV.Width, locCLV.Height)
Else
RaiseException("[GetViewDim] Unknown View "&GetType(aObject), False, True)
End If
End If
Return Result
End Sub
I thought I could use:
B4X:
if aObject is Activity then
private locActivity as Activity
locActivity = aObject
Result.Initialize(locActivity.Left, locActivity.Top, locActivity.Width, locActivity.Height)
else if aObject is View then
Private locView As View
locView = aObject
Result.Initialize(locView.Left, locView.Top, locView.Width, locView.Height)
end if
end if
But all views (panel, button etc.) that are passed will execute:
"if aObject is Activity then"
It appears all Views Is Activity and Activity is View. This does not make sense to me because if I try and reference Activity as View it throws an exception:
"java.lang.ClassCastException: android.widget.FrameLayout$LayoutParams cannot be cast to anywheresoftware.b4a.BALayout$LayoutParams"
So is there a better way to detect between a View and Activity?
TIA