Android Question FindByTag

advansis

Active Member
Licensed User
Longtime User
Hi guys, first of all, Happy Easter to everybody!
I always used FindViewByTag to retrieve a standard view inside a container.
With non standard views (such, BUT NOT ONLY: CustomListViews) this functions seems not to work.
Is there a standard way to achieve my goal? I have to load several layouts inside an activity (one at a time, but they have different views inside).
In this code, the IS statement is useless...

B4X:
    For Each V As View In P.GetAllViewsRecursive
        If V Is CustomListView Then
            Return true '<-- This line is never reached !
        End If
    Next

Thanks in advance
 

josejad

Expert
Licensed User
Longtime User
Have you tried if Log(GetType(v)) gives you any clue?

B4X:
    For Each V As View In P.GetAllViewsRecursive
        Log(GetType(v))
        If V Is CustomListView Then
            Return true '<-- This line is never reached !
        End If
    Next

GetType (object As Object) As String

Returns a string representing the object's java type.
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Moved to the questions forum.

You don't need a library and a library will not help. It is a mistake to use libraries to interact with the layout.

Add this line after you load the layout with the CustomListView:
B4X:
CLV.AsView.Tag = CLV
This will allow you to later find it with:
B4X:
 For Each V As B4XView In P.GetAllViewsRecursive
        If V.Tag Is CustomListView Then
            Dim clv As CustomListView = v.Tag
        End If
    Next
Note that with XUI Views the tag is already set for you.
 
Upvote 0

advansis

Active Member
Licensed User
Longtime User
Thank you Erel, but I do not know, in my code, wich layout is loaded each time... Customlistviews can be 1, 2 or 3 (why not 10 ?) for each Activity. I would use also other non-standard custom views... I need a generic approach. (I use this Activity to view db data, bounded to an entity/map by tag values...) I really use few lines of code, always the same, but several layouts.

At the moment I forced my layouts to have only customlistviews named clv1,clv2 or clv3, and declared as global, (and so on) but it is a "dirty" approach.
 
Upvote 0

DeviousD

Member
Licensed User
Longtime User
i feel really silly asking but for me and others possibly :
Just for reference purposes, Erel what is the P in P.GetAllViewsRecursive
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…