Android Question [Solved] Height Challenge with BBCodeview and B4XRadiobutton

omo

Active Member
Licensed User
Longtime User
While trying to find a cross platform based radiobutton solution that can be useful in BBcodeview, B4XRadioButton and ASRadioButton came to mind after finding out legacy radiobutton may pose challenge when i finally settle with B4I soon. Three b4xradiobuttons from designer were loaded into panel to work together as group in BBcodeview. It worked as group in bbcodeview, but i found it difficult to adjust height of varying text. I employed different tricks that were not successful like using -2 height wrap with reflection as in legacy radiobutton, but failed to work and not even cross platform compactible with b4J where it complained about missing method. I decided to access individual b4xradiobutton and its label from panel. All i could achieve is this in the picture below which worked only partially in B4J, but did not work at all in B4A. It worked partialy in B4J because all b4xradiobuttons become inactive (not responding to click again).

1b4jonly2.jpg


I also used MeasureTextHeight and MeasureTextWidth, but found it difficult to integrate in BBcodeview environment since all B4XRadiobuttons and label i like to work with are inside panel and if individual B4Xradiobutton is accessed with pnl.Getview(0) or B4xRadioButton1.mBase.GetView(0) or similar, it loses its group attribute and even inactive as shown above.
What i like to achieve with this b4xradiobutton solution is like this image below irrespective of height of text.
1651136717068.png


Please, i will be happy if i can get a working sample for cross platform solution, below is my experimental code. In this experimental code, i work with B4J and B4A, but i will like it to work in B4I also to avoid too much headache when i finally pitch tent with B4I soon.
Thanks
 

Attachments

  • B4X RadioButtonnBBCodeviewn.zip
    188.9 KB · Views: 156
Last edited:
Solution
1681022217737.png


1. Add each radio button inside a panel. This disables the automatic handling of the buttons.
2.

B4X:
Sub Class_Globals
    Private Root As B4XView
    Private xui As XUI
    Private BBCodeView1 As BBCodeView
    Private TextEngine As BCTextEngine
    Private RadioButtonGroups As Map
End Sub

Public Sub Initialize
'    B4XPages.GetManager.LogEvents = True
End Sub

'This event will be called once, before the page becomes visible.
Private Sub B4XPage_Created (Root1 As B4XView)
    Root = Root1
    Root.LoadLayout("MainPage")
    TextEngine.Initialize(Root)
    RadioButtonGroups.Initialize
    BBCodeView1.Text = $"
${CreateRB("aa")} I also used MeasureTextHeight but found it difficult to integrate in BBcodeview environment...

Erel

B4X founder
Staff member
Licensed User
Longtime User
1680676082948.png


B4X:
Private Sub B4XPage_Created (Root1 As B4XView)
    Root = Root1
    Root.LoadLayout("MainPage")
    TextEngine.Initialize(Root)
    BBCodeView1.Text = $"
${CreateRB} I also used MeasureTextHeight but found it difficult to integrate in BBcodeview environment since all B4XRadiobuttons and label i like to work with are inside panel and if individual B4Xradiobutton is
accessed with pnl.Getview(0) or B4xRadioButton1.mBase.GetView(0) or similar, it loses its group attribute and even inactive as shown above.

${CreateRB} What i like to achieve with this b4xradiobutton solution is like this image below irrespective of height of text.

${CreateRB} akqfew kjlqjf lqkwfj lkqw fjklqw jflqkjwf 
qkwjflqklwf jqlkwj flqkw jflkq jflqkw jfqlkw f
"$
End Sub

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

Private Sub B4XRadioButton1_Checked
    For Each v As B4XView In BBCodeView1.Views.Values
        If v.Tag Is B4XRadioButton And v.Tag <> Sender Then
            v.Tag.As(B4XRadioButton).Checked = False
        End If
    Next
End Sub

Not exactly what you want but this is a simple solution that works more naturally with BCTextEngine.
A B4A example is attached.
 

Attachments

  • Project.zip
    15.2 KB · Views: 132
  • Like
Reactions: omo
Upvote 0

omo

Active Member
Licensed User
Longtime User
View attachment 140964

B4X:
Private Sub B4XPage_Created (Root1 As B4XView)
    Root = Root1
    Root.LoadLayout("MainPage")
    TextEngine.Initialize(Root)
    BBCodeView1.Text = $"
${CreateRB} I also used MeasureTextHeight but found it difficult to integrate in BBcodeview environment since all B4XRadiobuttons and label i like to work with are inside panel and if individual B4Xradiobutton is
accessed with pnl.Getview(0) or B4xRadioButton1.mBase.GetView(0) or similar, it loses its group attribute and even inactive as shown above.

${CreateRB} What i like to achieve with this b4xradiobutton solution is like this image below irrespective of height of text.

${CreateRB} akqfew kjlqjf lqkwfj lkqw fjklqw jflqkjwf
qkwjflqklwf jqlkwj flqkw jflkq jflqkw jfqlkw f
"$
End Sub

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

Private Sub B4XRadioButton1_Checked
    For Each v As B4XView In BBCodeView1.Views.Values
        If v.Tag Is B4XRadioButton And v.Tag <> Sender Then
            v.Tag.As(B4XRadioButton).Checked = False
        End If
    Next
End Sub

Not exactly what you want but this is a simple solution that works more naturally with BCTextEngine.
A B4A example is attached.
Whaoo, thank you Erel! This your solution is unique in its nature and has opened my eyes to another programming logic. When combined with other solutions received on other related thread, I can now achieve better solution than what I initially set to acheive. I appreciate.
 
Upvote 0

omo

Active Member
Licensed User
Longtime User
View attachment 140964

B4X:
Private Sub B4XPage_Created (Root1 As B4XView)
    Root = Root1
    Root.LoadLayout("MainPage")
    TextEngine.Initialize(Root)
    BBCodeView1.Text = $"
${CreateRB} I also used MeasureTextHeight but found it difficult to integrate in BBcodeview environment since all B4XRadiobuttons and label i like to work with are inside panel and if individual B4Xradiobutton is
accessed with pnl.Getview(0) or B4xRadioButton1.mBase.GetView(0) or similar, it loses its group attribute and even inactive as shown above.

${CreateRB} What i like to achieve with this b4xradiobutton solution is like this image below irrespective of height of text.

${CreateRB} akqfew kjlqjf lqkwfj lkqw fjklqw jflqkjwf
qkwjflqklwf jqlkwj flqkw jflkq jflqkw jfqlkw f
"$
End Sub

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

Private Sub B4XRadioButton1_Checked
    For Each v As B4XView In BBCodeView1.Views.Values
        If v.Tag Is B4XRadioButton And v.Tag <> Sender Then
            v.Tag.As(B4XRadioButton).Checked = False
        End If
    Next
End Sub

Not exactly what you want but this is a simple solution that works more naturally with BCTextEngine.
A B4A example is attached.
Hello, sorry i didnt check it well yesterday; only one problem was solved; your solution was not in iteration loop for me to confirm if only one is checked in a group at a time. Is like i don't know how to put your solution in a loop for me to use. When i put it in a for i = 1 to 4 loop, i noticed it wasn't retaining one selection in one group. Below pic is what i got, only one button is being selected among (3 group of 4).
ne.jpg


However, what i like to achieve is to retain only one in a group as shown in second pic below. I like that your solution, but i will like if you can give me example code of how i can apply it in group of 3 or 4 radio buttons in 4 or 5 loop. I want one to be selected in a group like below:
1b4j.jpg

Thank you
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
1681022217737.png


1. Add each radio button inside a panel. This disables the automatic handling of the buttons.
2.

B4X:
Sub Class_Globals
    Private Root As B4XView
    Private xui As XUI
    Private BBCodeView1 As BBCodeView
    Private TextEngine As BCTextEngine
    Private RadioButtonGroups As Map
End Sub

Public Sub Initialize
'    B4XPages.GetManager.LogEvents = True
End Sub

'This event will be called once, before the page becomes visible.
Private Sub B4XPage_Created (Root1 As B4XView)
    Root = Root1
    Root.LoadLayout("MainPage")
    TextEngine.Initialize(Root)
    RadioButtonGroups.Initialize
    BBCodeView1.Text = $"
${CreateRB("aa")} I also used MeasureTextHeight but found it difficult to integrate in BBcodeview environment since all B4XRadiobuttons and label i like to work with are inside panel and if individual B4Xradiobutton is
accessed with pnl.Getview(0) Or B4xRadioButton1.mBase.GetView(0) Or similar, it loses its group attribute And even inactive As shown above.

${CreateRB("aa")} What i like to achieve with this b4xradiobutton solution is like this image below irrespective of height of text.

${CreateRB("bb")} akqfew kjlqjf lqkwfj lkqw fjklqw jflqkjwf 
qkwjflqklwf jqlkwj flqkw jflkq jflqkw jfqlkw f

${CreateRB("bb")} akqfew kjlqjf lqkwfj lkqw fjklqw jflqkjwf 
qkwjflqklwf jqlkwj flqkw jflkq jflqkw jfqlkw f

${CreateRB("bb")} akqfew kjlqjf lqkwfj lkqw fjklqw jflqkjwf 
qkwjflqklwf jqlkwj flqkw jflkq jflqkw jfqlkw f
"$
End Sub

Private Sub CreateRB (GroupKey As String) As String
    Dim pnl As B4XView = xui.CreatePanel("")
    pnl.SetLayoutAnimated(0, 0, 0, 40dip, 40dip)
    pnl.LoadLayout("RadioButton")
    Dim name As String = ("rb" & BBCodeView1.Views.Size)
    Dim rb As B4XRadioButton = pnl.GetView(0).Tag
    RadioButtonGroups.Put(rb, GroupKey)
    BBCodeView1.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)
    For Each v As B4XView In BBCodeView1.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
                rb.Checked = False
            End If
        End If
    Next
End Sub

Note that in the previous example the B4XRadioButton1_Checked sub wasn't needed.
 
Upvote 0
Solution

omo

Active Member
Licensed User
Longtime User
View attachment 141082

1. Add each radio button inside a panel. This disables the automatic handling of the buttons.
2.

B4X:
Sub Class_Globals
    Private Root As B4XView
    Private xui As XUI
    Private BBCodeView1 As BBCodeView
    Private TextEngine As BCTextEngine
    Private RadioButtonGroups As Map
End Sub

Public Sub Initialize
'    B4XPages.GetManager.LogEvents = True
End Sub

'This event will be called once, before the page becomes visible.
Private Sub B4XPage_Created (Root1 As B4XView)
    Root = Root1
    Root.LoadLayout("MainPage")
    TextEngine.Initialize(Root)
    RadioButtonGroups.Initialize
    BBCodeView1.Text = $"
${CreateRB("aa")} I also used MeasureTextHeight but found it difficult to integrate in BBcodeview environment since all B4XRadiobuttons and label i like to work with are inside panel and if individual B4Xradiobutton is
accessed with pnl.Getview(0) Or B4xRadioButton1.mBase.GetView(0) Or similar, it loses its group attribute And even inactive As shown above.

${CreateRB("aa")} What i like to achieve with this b4xradiobutton solution is like this image below irrespective of height of text.

${CreateRB("bb")} akqfew kjlqjf lqkwfj lkqw fjklqw jflqkjwf
qkwjflqklwf jqlkwj flqkw jflkq jflqkw jfqlkw f

${CreateRB("bb")} akqfew kjlqjf lqkwfj lkqw fjklqw jflqkjwf
qkwjflqklwf jqlkwj flqkw jflkq jflqkw jfqlkw f

${CreateRB("bb")} akqfew kjlqjf lqkwfj lkqw fjklqw jflqkjwf
qkwjflqklwf jqlkwj flqkw jflkq jflqkw jfqlkw f
"$
End Sub

Private Sub CreateRB (GroupKey As String) As String
    Dim pnl As B4XView = xui.CreatePanel("")
    pnl.SetLayoutAnimated(0, 0, 0, 40dip, 40dip)
    pnl.LoadLayout("RadioButton")
    Dim name As String = ("rb" & BBCodeView1.Views.Size)
    Dim rb As B4XRadioButton = pnl.GetView(0).Tag
    RadioButtonGroups.Put(rb, GroupKey)
    BBCodeView1.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)
    For Each v As B4XView In BBCodeView1.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
                rb.Checked = False
            End If
        End If
    Next
End Sub

Note that in the previous example the B4XRadioButton1_Checked sub wasn't needed.
Thank you Erel, it works on the first run, i have started adjusting for my need. I tested it on android and B4J, it works flawlessly. I am so grateful.
pc2.jpg
 
Upvote 0
Top