How do I find the activity of a given view, if I'm in a code module?
I'm passing a view to a sub in a code module, and I also need the view's activity. If I'm in an activity module, I have the "Activity" object handy, but not in a code module.
I could pass the activity as a sub parameter, but I'm already passing the view, and I'm hoping I can just find the view's activity without having to pass it explicitly.
The following code works for normal layouts, but seemingly not for those with a scrollview:
I suspect that the test for "is Activity" is stumbling when it hits the scrollview in the layout hierarchy.
Any help much appreciated. Thanks!
I'm passing a view to a sub in a code module, and I also need the view's activity. If I'm in an activity module, I have the "Activity" object handy, but not in a code module.
I could pass the activity as a sub parameter, but I'm already passing the view, and I'm hoping I can just find the view's activity without having to pass it explicitly.
The following code works for normal layouts, but seemingly not for those with a scrollview:
B4X:
'return the activity that the view lives in
Sub getActivityFromView(viewArg As View) As Activity
If viewArg.Parent Is Activity Then
Return viewArg.parent
Else
Return getActivityFromView(viewArg.Parent)
End If
End Sub
I suspect that the test for "is Activity" is stumbling when it hits the scrollview in the layout hierarchy.
Any help much appreciated. Thanks!