Android Question Get Custom View

BarryW

Active Member
Licensed User
Longtime User
How to get a custom view from a panel or parent.

I created a layout with a customview. Then I try to load the layout inside a panel. How to get the customview now? like dim cv as custoview = Panel.GetView(0).

I got this error..

java.lang.ClassCastException: anywheresoftware.b4a.BALayout cannot be cast to com.napps.stl.customview
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
cv as AutoTextSizeLabel = Panel.GetView(0)
This will not work. The custom view class is not a view by itself.

A simple way to solve it is by setting the Tag property of the base panel or in the case of AutoTextSizeLabel the Label (the base panel is removed) to the class instance in DesignerCreateView:
B4X:
mLBL.Tag = Me
This allows you to get it with:
B4X:
Dim cv As AutoTextSizeLabel = Panel.GetView(0).Tag
 
Upvote 1
Top