Android Question get AutoTextSizeLabel view with FindViewByTag function.

Erel

B4X founder
Staff member
Licensed User
Longtime User
A custom view class instance is not a view by itself. This means that you cannot cast a view to a custom view class.

You can use a custom type to store all the information needed.

1. Add to class_globals
B4X:
Type AutoTextSizeLabelTag (Name As String, Instance As AutoTextSizeLabel)

2. Add to DesignerCreateView:
B4X:
Dim tag As AutoTextSizeLabelTag
tag.Initialize
tag.Name = Base.Tag
tag.Instance = Me
lbl.Tag = tag

3. Add to activity code:
B4X:
Sub GetAutoTextSizeLabelFromTag(tag As String) As AutoTextSizeLabel
   Dim res As AutoTextSizeLabel
   For Each v As View In Activity.GetAllViewsRecursive
       If v.Tag Is AutoTextSizeLabelTag Then
           Dim atag As AutoTextSizeLabelTag = v.Tag
           If atag.Name = tag Then Return atag.Instance
       End If
   Next
   Return res
End Sub
 
Upvote 0
Top