Android Question Stepping on B4XFloatTextField Accept and Cancel Buttons

mmieher

Active Member
Licensed User
Longtime User
I seem to be inadvertently disabling the Accept and Cancel buttons in a B4XTextFloatField. This code works fine:
B4X:
    EditMtgPage.Initialize("EditMtg")
    Root.AddView(EditMtgPage,0,0,100%x,100%y)
    EditMtgPage.LoadLayout("EditMtg")
    '''' B4M.SetAllTags(EditMtgPage)    ' calling this effs up Accept and Cancel buttons

But if I uncomment that last line, this seemingly innocent sub "disables" the Accept and Cancel buttons. They appear, but do nothing when clicked. The _EnterPressed event is not fired for Accept.

Note that this sub does not touch the B4XFloatTextFields in my layout. They do not already have a Tag specified in the Designer, so I have no idea what is going on.
B4X:
Public Sub SetAllTags(pView As B4XView)
    LogSub("SetAllTags: " & pView.NumberOfViews)
    
    For Each v As B4XView In pView.GetAllViewsRecursive
        If v.Tag <> Null Then        '    create tag map
            Dim strTag As String = v.Tag
            If strTag.Length > 0 And strTag.Length < 1000 Then    '    i do not like this arbitrary 1000 thing
            ''If strTag.Length > 0 Then    '    i would like this but do not know what that one big thing is.  Not a Layout ...
                Log("strTag:   " & strTag)
                    
                Dim tagStart As Int = strTag.IndexOf("[")
                If tagStart > 2 Then
                        
                    Dim newTag As Object
                    Dim jj As Int = strTag.IndexOf2("]",tagStart)
                    If jj > 0 Then
                        newTag = strTag.SubString2(tagStart+1,jj)
                        Log("newTag = " & newTag)
                    Else
                        newTag = v.Tag
                    End If
                    v.Tag = newTag
                        
                    strTag = strTag.SubString2(0,tagStart)
                    Log("new strTag = " & strTag)
                        
                End If
                
                Dim tagMap As Map = CreateMap("vxname":strTag,"vxtag":v.Tag)
                v.Tag = tagMap
                
            End If
        End If    '    v.tag <> null
        Log("new tag:  " & v.Tag)
        
    Next

End Sub

In case you are wondering "What the hell?" this is part of a scheme to get the fricking field name programmatically and still be able to shove something else in the "tag" value.
 

William Lancee

Well-Known Member
Licensed User
Longtime User
B4X:
        editorlayer.Tag = B4XFloatTextField1
        Log(editorlayer.Tag.As(String).length)  'In my app this displays 89329

I assume you start in the designer by placing names of views in their tags.
Then you want to read all the views you have created and replace the string name in the tag with a map, so that you can also put other things in the tag.
I have done something similar.

The loop in your Sub is recursive, so that not just the views you created but all views in all complex custom views too,
some will have a reference to the custom view itself. This is not what you want.

Filter the loop using GetType(vw.tag).Contains("String"), it will tell you if the tag is a string or not (Don't use "Is" for this).

I believe you have replaced a critical reference to a custom view class instance with a map.
To know more, one would have to fully understand how each custom view is implemented.

Others may have a better answer.
 
Upvote 0

mmieher

Active Member
Licensed User
Longtime User
B4X:
        editorlayer.Tag = B4XFloatTextField1
        Log(editorlayer.Tag.As(String).length)  'In my app this displays 89329

I assume you start in the designer by placing names of views in their tags.
Then you want to read all the views you have created and replace the string name in the tag with a map, so that you can also put other things in the tag.
I have done something similar.

The loop in your Sub is recursive, so that not just the views you created but all views in all complex custom views too,
some will have a reference to the custom view itself. This is not what you want.

Filter the loop using GetType(vw.tag).Contains("String"), it will tell you if the tag is a string or not (Don't use "Is" for this).

I believe you have replaced a critical reference to a custom view class instance with a map.
To know more, one would have to fully understand how each custom view is implemented.

Others may have a better answer.
Thank you, William! I will give it a shot! Now to think of a safe "String" ...
 
Upvote 0

William Lancee

Well-Known Member
Licensed User
Longtime User
Also, I found that it was better to keep a global B4XOrderedMap of Views indexed by names.
I do the same as you do but then put the (name, view) pair in a global B4XOrederedMap, rather than in the tag.

This releases the tag for other purposes. Just a suggestion.
 
Upvote 0

mmieher

Active Member
Licensed User
Longtime User
I did everything you originally said and all is working. Will have to bone up on a B4XOrderedMap ...
 
Upvote 0
Top