Android Question Can one access individual control(i.e Radiobutton) from panel without loosing "group" attribute?

omo

Active Member
Licensed User
Longtime User
Purpose of using panel for radiobutton is to group those radiobuttons together, however; there are times one needs to access one radiobutton from this group for more specific coding purpose, is it possible or is there any technique one can use to reference one single radiobutton from panel without loosing that grouping attribute inherited from panel? I used pnl.Getview(0), dd.GetViewByName(pnl, "RadioButton1") or similar but were found to loose that inherited panel "grouping" attribute. Is there any other way different from above or can i get sample code on how it can be done? For example: If we load 3-radiobuttons from designer into panel (pnl), it will work as group, but once the three buttons are accessed thus:
Dim radiobutton1 as radiobutton = pnl.Getview(0)
Dim radiobutton2 as radiobutton = pnl.Getview(1)
Dim radiobutton3 as radiobutton = pnl.Getview(2)

radiobuton1, 2 and 3 will loose that panel grouping identity which render them unusable in some programming logic solution

or aside using panel to group radiobutton, is there any other ways either via Javacode or other means different from panel that will not loose inherited "group" attribute when accessed individually for further coding?
 
Last edited:

omo

Active Member
Licensed User
Longtime User
Could you post a small project?
Ok, the experimental code where i cut the snippet i sent to you last is attached below, i used it in B4J, that of B4A is not displaying yet. This is B4xradiobutton; you can apply your logic to legacy radiobutton or B4Xradiobutton, Feel free to use either b4xradiobutton or normal type. Thank you
 

Attachments

  • B4XRadioSolution.zip
    187.5 KB · Views: 139
Upvote 0

William Lancee

Well-Known Member
Licensed User
Longtime User
You have got us going through hoops for you.
Just adjust the tag to include two parameters. There are already examples of this in the code we posted.
I'm out.
 
  • Like
Reactions: omo
Upvote 0

omo

Active Member
Licensed User
Longtime User
You have got us going through hoops for you.
Just adjust the tag to include two parameters. There are already examples of this in the code we posted.
I'm out.
Hoops? Not really, if one solution solves my problem, why will I ask for more ? Being a new trick, it must always bring along more room for clearification; that's why. You have tried, thank you; I appreciate your effort. Trial-and-error will solve the remaining
Regards
 
Last edited:
Upvote 0

Mahares

Expert
Licensed User
Longtime User
The more I read this thread the more I see xCustomlistview written all over it, with items as panels composed of 3 B4XRadioButtons each , unless I am missing the big picture. I think , if the OP explains in plain English exactly what he wants to do with a clearer explanation and a screenshot of the end result, perhaps it can be addressed again. If xCustomlistview is not applicable here, please disregard my post.
 
Upvote 0

omo

Active Member
Licensed User
Longtime User
The more I read this thread the more I see xCustomlistview written all over it, with items as panels composed of 3 B4XRadioButtons each , unless I am missing the big picture. I think , if the OP explains in plain English exactly what he wants to do with a clearer explanation and a screenshot of the end result, perhaps it can be addressed again. If xCustomlistview is not applicable here, please disregard my post.
@Mahares, thank you. How do I explain better for you? Ok, let me put it this way, this is what I am trying to acheive from other threads I opened yesterday maybe you will understand better if you read any below. I just need B4X solution:



I am opened to new idea and trick possibilities since this is what we do from time to time. Aside that, solution like this can help others that may need related help in future. Seeing possibility in xcustomlostview wouldnt be bad idea if I can see sample code to see how it will work with varying long text. At point in time one can decide best and fast solution to get the work done.

I will like for example 3/4 b4xradiobuttons in a group and you can loop it i.e like for i = 1 to 4, so that we can have about 12 or 16 radiobuttons all together. When you click each radiobutton in a group, it should retain one selection at a time
in each group. It should be demostrated on bbcodeview environment or as you deem fit (to avoid bbcodeview scrolling complication with xcustomlistview) so far it can adjust with long varying text irrespective of height of text. That is exactly in summary what I am trying to achieve.
Thank you
 
Last edited:
Upvote 0

Mahares

Expert
Licensed User
Longtime User
Seeing possibility in xcustomlostview wouldnt be bad idea if I can see sample code to see how it will work with varying long text. At point in time one can decide best and fast solution to get the work done.

How about an xCustomlistview with 4 panels, each panel has 3 B4XRadioButtons. When you click on any button it displays long text that you can scroll through for viewing using the B4XLongTextTemplate of XUI Views. ANy button you check displays a different text with different length. You can scroll the text and make it as wide and as high as the screen. SInce you are looking for ideas??
1680815722415.png




1680815832088.png
 
Upvote 0

omo

Active Member
Licensed User
Longtime User
How about an xCustomlistview with 4 panels, each panel has 3 B4XRadioButtons. When you click on any button it displays long text that you can scroll through for viewing using the B4XLongTextTemplate of XUI Views. ANy button you check displays a different text with different length. You can scroll the text and make it as wide and as high as the screen. SInce you are looking for ideas??
View attachment 141026



View attachment 141027
First of all, thank you for your hard work and williness to help. I value your precious time and i really appreciate deep down my heart, however; where I am having problem exactly is how to accommodate long text in place of option 1, 2 or 3 or on another label put beside B4xradiobutton after removing B4xradiobutton mlabel and not as extra dialogbox or msgbox to display the text when clicked.

How this your solution will fit my context is if that long text can show up on b4xradiobutton1.mlabel or other label placed beside the b4xradiobutton1. Once the long text show up, if the panel1 can stretch or adjust to accommodate all the long text before b4xradiobutton2 then come up so we can have something similar to b4xradiobutton2.Top = b4xradiobutton1.Top + b4xradiobutton1.height; which will be after measureheight of long text has been computed. If panel and subsequent b4xradiobutton to long text can adjust appropriately, it will fit my present requirement as alternative to bbcodeview so far one button is retained in each group when clicked and it is b4xsolution
 
Last edited:
Upvote 0

ivanomonti

Expert
Licensed User
Longtime User
when I have to get a reference of a panel or more panels without losing references, I get it with this method, I don't know if this is useful for you, also because I don't speak English very well

B4X:
    Dim Pane As B4XView
    
    For Each v As B4XView In Pane.GetAllViewsRecursive
        If v Is Button Then
            If v.As(Button).Tag = 123 Then
                v.As(Button).Text = "Hola"
            End If
        End If
    Next
 
Upvote 0

omo

Active Member
Licensed User
Longtime User
when I have to get a reference of a panel or more panels without losing references, I get it with this method, I don't know if this is useful for you, also because I don't speak English very well

B4X:
    Dim Pane As B4XView
 
    For Each v As B4XView In Pane.GetAllViewsRecursive
        If v Is Button Then
            If v.As(Button).Tag = 123 Then
                v.As(Button).Text = "Hola"
            End If
        End If
    Next
Oh, thank you so much, it will be useful and your English or translation is not bad. @teddybear was trying to suggest something like this yesterday:
For i= 0 To Pnl.NumberOfViews -1
PnlGetView(i).Tag = "Pnl"
Next
to keep hold of controls in a panel without loosing refrence. I will use your own in place to see if it fits what we were trying to achieve with that technique. Thank you so much @ivanomonti
 
Last edited:
Upvote 0

Mahares

Expert
Licensed User
Longtime User
alternative to bbcodeview so far one button is retained in each group when clicked and it is b4xsolution
Your requirements and explanation were well presented. Have you by any chance taken a look at CLVExpandable. I am not sure at this point if it can fit in your scenarios, nevertheless worth a look, but if I get some time, I might play with it.
 
Upvote 0

omo

Active Member
Licensed User
Longtime User
Your requirements and explanation were well presented. Have you by any chance taken a look at CLVExpandable. I am not sure at this point if it can fit in your scenarios, nevertheless worth a look, but if I get some time, I might play with it.
CLVExpandable will just expand my coding headache (although, I may be wrong) and won't fit well in area where I want to apply it. Bbcodeview still remains shortest coding approach if only I can access individual B4xradiobutton on a panel without loosing its grouping attribute inherited from panel since autotext height adjustment is taken care off. Xcustomlistview can serve as good planB if measuretexthheight can be taken care off. If you check one of the earlier links I posted here, I succeeded in adjusting or moving B4xradiobutton2 to end of long text, but I found out all B4xradiobutton then became inactive.

Erel gave out one solution which could have been fantastic solution, but I later found out those b4xradiobuttons were not looped/iterated to test if it retains one click in a group. And I don't really know how to rework it as group to solve that problem. Thank you for your time, that your solution will be enough to solve some people problem in future and it may help those who want to expand it to solve this present problem, you can please attach your source code sample to where you put the screenshot by editing it.
 
Upvote 0

teddybear

Well-Known Member
Licensed User
Ok, the experimental code where i cut the snippet i sent to you last is attached below, i used it in B4J, that of B4A is not displaying yet. This is B4xradiobutton; you can apply your logic to legacy radiobutton or B4Xradiobutton, Feel free to use either b4xradiobutton or normal type. Thank you
I read your code, if you use RadioButton instead of B4Xradiobutton in layout , the group behavior of RadioButtons will work in BBCodeView.

that's because RadioButton can be cast to B4XView and B4Xradiobutton can't be.( B4Xradiobutton is customview)

when we get a B4XView from Panel using GetView(), the B4xView of RadioButton can retain the group behavior, and the B4xView from B4xRadioButton will lose the group behavior
 
Upvote 0

omo

Active Member
Licensed User
Longtime User
I read your code, if you use RadioButton instead of B4Xradiobutton in layout , the group behavior of RadioButtons will work in BBCodeView.

that's because RadioButton can be cast to B4XView and B4Xradiobutton can't be.( B4Xradiobutton is customview)

when we get a B4XView from Panel using GetView(), the B4xView of RadioButton can retain the group behavior, and the B4xView from B4xRadioButton will lose the group behavior
You are right! I sensed that while working with it too. That is why I encouraged you in my previous post to feel free to apply that your method to legacy radiobutton so I can see how it works out. But aside B4J, does your solution work the same in B4A? If it works in B4A and B4J, that means major headache is solved in simpler way close to logic I can easily manipulate. I can just use @William Lancee label wonderful trick to acheive that of B4I. Although, I will still like to see possible solutions around B4xradiobutton/AS_Radiobutton because of enhanced effects. Please, help me attach your modified code, so I can test it in B4A also. Thank you
 
Upvote 0

omo

Active Member
Licensed User
Longtime User
I read your code, if you use RadioButton instead of B4Xradiobutton in layout , the group behavior of RadioButtons will work in BBCodeView.

that's because RadioButton can be cast to B4XView and B4Xradiobutton can't be.( B4Xradiobutton is customview)

when we get a B4XView from Panel using GetView(), the B4xView of RadioButton can retain the group behavior, and the B4xView from B4xRadioButton will lose the group behavior
I just remember I did that before with normal radiobutton, it worked only in B4J but didn't work in B4A. But because I needed B4x solution, I ignored looking at direction of conventional radiobutton. If you remove or uncomment your code from the B4J I sent to you and replace B4xradiobutton with normal radiobutton, it will still work well in B4J only without your code, but it never works in B4A.

The only solution that works in B4A with code I sent to you is if you uncomment shorter str string and commented off the other one and adjust bbcodeview put for it, it will work in B4A, but once you access each control in panel one by one with pnl.getview(x) and use them as shown in the code, it never works in B4A. If you have any other solution that works with B4A as well with conventional radiobutton or B4xradiosolution, kindly let me know
 
Last edited:
Upvote 0
Top