Android Question [Solved] Problem with Getview based on Desinger View Tree or Otherwise

omo

Active Member
Licensed User
Longtime User
In this link below @ https://www.b4x.com/android/forum/t...odeview-and-b4xradiobutton.147245/post-933746
Erel was able to solve b4xradiobutton height challenge. It was cool and worked well when there is no other control on bbcodeview at designer. However, when there are more controls on bbcodeview as indicated in the image below in the designer.
vtree.jpg



The code is giving error only on two heighighted statements in the code's Getview(0) as shown in the code below

B4X:
Private Sub CreateRB (GroupKey As String) As String
    Dim pnl As B4XView = xui.CreatePanel("")
    pnl.SetLayoutAnimated(0, 0, 0, 30dip, 30dip) '40
    pnl.LoadLayout("RadioButton")
    Dim name As String = ("rb" & BBCodeView3.Views.Size)
    Dim rb As B4XRadioButton = pnl.GetView(0).Tag
    RadioButtonGroups.Put(rb, GroupKey)
    BBCodeView3.Views.Put(name, pnl)
    Return $"[View=${name} Vertical=10/]"$
End Sub

Private Sub B4XRadioButton1_Checked
    Dim CheckedRB As B4XRadioButton = Sender
  
    Dim CurrentGroup As String = RadioButtonGroups.Get(CheckedRB)
    Log("current group: " & CurrentGroup)
    'Log("CheckedRB1: " & CheckedRB)
  
  
    For Each v As B4XView In BBCodeView3.Views.Values
      
       If v.GetView(0).Tag Is B4XRadioButton Then
            Dim rb As B4XRadioButton = v.GetView(0).Tag
          
        If rb <> CheckedRB And RadioButtonGroups.Get(rb) = CurrentGroup Then
                Log("You clicked: " & v.GetView(0).Tag)
                rb.Checked = False
            End If

          
        End If
    Next
    End sub

I tried using v.Getview(0).Getview(1).tag and used recurrssive approach, but coudn't get it resolve. How can that segment of code be rewritten based on designer view tree above for BBCodeView3 so that my b4xradiobutton can work properly ?
 
Last edited:

Mahares

Expert
Licensed User
Longtime User
How can that segment of code be rewritten based on designer view tree above for BBCodeView3 so that my b4xradiobutton can work properly ?
Based on what I see showing on your tree configuration: This line in CreateRB sub:
B4X:
Dim rb As B4XRadioButton = pnl.GetView(0).Tag
Should be:
B4X:
Dim rb As B4XRadioButton = pnl. GetView(0). GetView(1).GetView(0).Tag
 
Upvote 0

omo

Active Member
Licensed User
Longtime User
Based on what I see showing on your tree configuration: This line in CreateRB sub:
B4X:
Dim rb As B4XRadioButton = pnl.GetView(0).Tag
Should be:
B4X:
Dim rb As B4XRadioButton = pnl. GetView(0). GetView(1).GetView(0).Tag
Thank you @Mahares, i tried it before and even again after i received your message to reconfirm, but is not working yet. Below is how i modified it. I

B4X:
Private Sub CreateRB (GroupKey As String) As String
    Dim pnl As B4XView = xui.CreatePanel("")
    pnl.SetLayoutAnimated(0, 0, 0, 30dip, 30dip) '40
    pnl.LoadLayout("RadioButton")
    Dim name As String = ("rb" & BBCodeView3.Views.Size)
    Dim rb As B4XRadioButton = pnl.GetView(0).GetView(1).GetView(0).Tag
    RadioButtonGroups.Put(rb, GroupKey)
    BBCodeView3.Views.Put(name, pnl)
    Return $"[View=${name} Vertical=25/]"$
End Sub

Private Sub B4XRadioButton1_Checked
    
    Dim CheckedRB As B4XRadioButton = Sender
    
    Dim CurrentGroup As String = RadioButtonGroups.Get(CheckedRB)
    Log("current group: " & CurrentGroup)
    'Log("CheckedRB1: " & CheckedRB)
    For Each v As B4XView In BBCodeView3.Views.Values
        If v.GetView(0).GetView(1).GetView(0).Tag Is B4XRadioButton Then 'Return v
            Dim rb As B4XRadioButton = v.GetView(0).GetView(1).GetView(0).Tag
        If rb <> CheckedRB And RadioButtonGroups.Get(rb) = CurrentGroup Then
'                Log("You clicked: " & v.GetView(0).Tag)
            
                rb.Checked = False
        End If
        End If
    Next
    End Sub
 
Upvote 0

Mahares

Expert
Licensed User
Longtime User
Below is how i modified it
I don;t think you needed to change the: Private Sub B4XRadioButton3_Checked sub.
Keep it like you have it in post #1. DId you try that. If that does not help, then, I am not sure. Maybe someone who worked with you on that BBCodeview project can help.
EDIT: I just noticed that you call the radio button: B4XRadioButton1 in post 3 and you call it: B4XRadioButton3 in post 1. Why???
 
Last edited:
Upvote 0

omo

Active Member
Licensed User
Longtime User
I don;t think you needed to change the: Private Sub B4XRadioButton3_Checked sub.
Keep it like you have it in post #1. DId you try that. If that does not help, then, I am not sure. Maybe someone who worked with you on that BBCodeview project can help.
EDIT: I just noticed that you call the radio button: B4XRadioButton1 in post 3 and you call it: B4XRadioButton3 in post 1. Why???
Thank you for that observation, i actually used correct one in the code with no success. It is B4XRadioButton1 as shown below, i have corrected post 1. The problem is just in that two highlighted statements. If the two highlighted statements are commented out, other codes run without problem, but the two statements hold key to correctness and functioning of entire code. Thank you so much @Mahares, yes, Erel is the original author of that code, he will likely see it tomorrow or Monday. The code works well if there is no other controls with bbcodeview. I even used his trick to make AS_RadioButton work with little modification, but i am sure i will have similar problem of Getview(0).tag
22.png
 
Upvote 0

Mahares

Expert
Licensed User
Longtime User
Erel is the original author of that code, he will likely see it tomorrow or Monday.
OK, good luck @omo . I am sure Erel will be of help to you. In the meantime, it might be a good idea for you to post those 2 subs the way they shold be posted with B4XRadioButton1 and also show the error message, because you mention error , but not what it is. Maybe someone else can spot it when posted more clearly. You can always post your project. Most developers can spot problems from a project easier than from a snippet
 
Last edited:
Upvote 0

omo

Active Member
Licensed User
Longtime User
OK, good luck @omo . I am sure Erel will be of help to you. In the meantime, it might be a good idea for you to post those 2 subs the way they shold be posted with B4XRadioButton1 and also show the error message, because you mention error , but not what it is. Maybe someone else can spot it when posted more clearly. You can always post your project. Most developers can spot problems from a project easier than from a snippet
Sorry, @Mahares for late response, i was actually trying to come out with something when i got another idea and motivation through your last message. The actual code where i am trying to implement Erel's solution is lengthy, then i decided to strip off all panels and controls on that designer at post one so it will remain only bbcodeview. With only bbcodeview like Erel's solution, i still got same error which means there may be other things causing error or conflict. I have been doing that investigation, but yet to find out. I will mark the thread as : "Don't Touch Yet" until i finish my investigation to update the thread or raize another one. I am son grateful to you, without that your statement, i wouldn't give second thought because i have been so bored with sleepless trial and error
 
Upvote 0

omo

Active Member
Licensed User
Longtime User
I was able to detect where the problem emerged from by 3am on Saturday's midnight local time. I duplicated my program to another folder so i could use it for trial and error by stripping off all controls and panels found on bbcodeview at designer. i then started commenting off and un-commenting codes until i traced it to another button code i had written before on my program before beginning to integrate Erel's solution. Problem is not in the Erel's solution, it is just a conflict with thts: BBCodeView3.Views.Put("btnb" & i, btnb). when i commented off this, every thing worked well. Problem was not v.Getview(0) issues i was suspecting before. Erel's solution was able to resolve designer three view with default v.Getview(0) without problem. Having detected the problem, i discarded the duplicated work and went back to my original program folder to comment off the line because i have damaged pilot copy beyond repair. Everything has now worked so far, i will look for way to get the conflicting button back to its position without conflict. Thank you @Erel, @Mahares and all forum members. Regards
 
Upvote 0
Top