Android Question Why is this button breaking the law of BBCodeview/BCTextengine?

omo

Active Member
Licensed User
Longtime User
In normal button creation on BBCodeview based on Erel these steps are needed:
Step 1:
Dim btnb As Button
btnb.Initialize ("btnb")
btnb.Text = "View Answer"
btnb.SetLayoutAnimated(0, 0, 0, 100dip, 80dip)


Step 2: follow by this: BBCodeView1.Views.Put("btnb", btnb)

Step 3: place button view where you need it thus: [View=btnb vertical = 10 /]

In this context, i am trying to make 3-buttons beside view button in loop at the right hand-side as shown in demo picture below and use sender to get each button id, but [View=btnb vertical = 10 /] is not working. Please, what should i have done differently?
bb2.jpg

I want button to display at the right-hand-side of each View Result link instead

Here is the attached source code

B4X:
#Region  Project Attributes
    #ApplicationLabel: B4A Example
    #VersionCode: 1
    #VersionName:
    'SupportedOrientations possible values: unspecified, landscape or portrait.
    #SupportedOrientations: unspecified
    #CanInstallToExternalStorage: False
#End Region

#Region  Activity Attributes
    #FullScreen: False
    #IncludeTitle: True
#End Region



Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.

End Sub

Sub Globals
    'These global variables will be redeclared each time the activity is created.
    'These variables can only be accessed from this module.
    Private BBCodeView1 As BBCodeView
    Private TextEngine As BCTextEngine
    Public name, country, status As String
    Private Spinner1 As Spinner
End Sub

Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    'Activity.LoadLayout("Layout1")
    Activity.LoadLayout("bblooptest2")
    TextEngine.Initialize(Activity)
    'BBCodeView1.TextEngine.WordBoundaries = "&*+-/<>=\{}" & TAB & CRLF & Chr(13)
    BBCodeView1.TextEngine.WordBoundariesThatCanConnectToPrevWord = $"'.,":?;!"$
    
    BBCodeView1.sv.ScrollViewOffsetY = 0
    
    Dim btnb As  Button
    btnb.Initialize ("btnb")
    btnb.Text = "View Answer"
    btnb.SetLayoutAnimated(0, 0, 0, 100dip, 80dip)
    
    
    BBCodeView1.Views.Put("btnb", btnb)
    
    '[View=btnb vertical = 10 /]
    
    Dim str As String
    For i = 0 To 2
        name  = "University of Lagos"
        country  = "Increased agricultural marketing and farming" ' user_map.Get("country")
        status = "Inventory management system" ' user_map.Get("status")
        Spinner1.Add(name)
      
        str= str & $"${CRLF}${CRLF}${name}${CRLF}${country}${CRLF}${status}${CRLF}[url = "https://www.google.com"]View Result [/url][Alignment=right]View=${btnb}[/Alignment]"$
                        
    Next
    BBCodeView1.Text =   $"[Color=#ff0000][TextSize=17][Alignment=left][b]${str}[/b][/Alignment][/TextSize][/Color]${CRLF}"$ & ""
    
End Sub


Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub
 

Attachments

  • testbbcodeloop2.zip
    9.9 KB · Views: 153

Erel

B4X founder
Staff member
Licensed User
Longtime User
Please use [code]code here...[/code] tags when posting code.

Several mistakes here:
1. You have created a single button. There is no way that you will be able to add it multiple times.
2. View is a tag
3. You need to pass the view key in the bbcode:
B4X:
        str= str & $"${CRLF}${CRLF}${name}${CRLF}${country}${CRLF}${status}
[url = "https://www.google.com"]View Result [/url][Alignment=right][View=btnb/][/Alignment]"$

4. No need for these CRLFs.
 
Upvote 0

omo

Active Member
Licensed User
Longtime User
Please use [code]code here...[/code] tags when posting code.

Several mistakes here:
1. You have created a single button. There is no way that you will be able to add it multiple times.
2. View is a tag
3. You need to pass the view key in the bbcode:
B4X:
        str= str & $"${CRLF}${CRLF}${name}${CRLF}${country}${CRLF}${status}
[url = "https://www.google.com"]View Result [/url][Alignment=right][View=btnb/][/Alignment]"$

4. No need for these CRLFs.

Thank you Erel, I had passed it like [View = btnb /] before and even now after your message without success. I tried several other tricks before i finally put this view =${btnb}, which i knew was not the right way, but at least it shows me something. below is the error i keep getting and i don't know the view is referring to. if panel is there, i could have tried something like: panel1.removeview; my code is attached earlier.i don't know the view is referring to and how to resolve the problem. As per CRLFs , i put it to create space exactly as displayed in the attached picture , this is just a demo, actual data is sourced from database. I want button after each record as displayed in the picture, that is why i put it under loop

B4X:
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
bbcodeparser_texttorun (java line: 918)
java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child's parent first.
    at android.view.ViewGroup.addViewInner(ViewGroup.java:3337)
    at android.view.ViewGroup.addView(ViewGroup.java:3208)
    at android.view.ViewGroup.addView(ViewGroup.java:3188)
    at anywheresoftware.b4a.objects.PanelWrapper.AddView(PanelWrapper.java:65)
    at anywheresoftware.b4a.objects.B4XViewWrapper.AddView(B4XViewWrapper.java:323)
    at b4a.example.bbcodeparser._texttorun(bbcodeparser.java:918)
    at b4a.example.bbcodeparser._createruns(bbcodeparser.java:142)
    at b4a.example.bbcodeview._parseanddraw(bbcodeview.java:361)
    at b4a.example.bbcodeview._settext(bbcodeview.java:407)
    at b4a.example.main._activity_create(main.java:397)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:511)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:213)
    at b4a.example.main.afterFirstLayout(main.java:105)
    at b4a.example.main.access$000(main.java:17)
    at b4a.example.main$WaitForLayout.run(main.java:83)
    at android.os.Handler.handleCallback(Handler.java:605)
    at android.os.Handler.dispatchMessage(Handler.java:92)
    at android.os.Looper.loop(Looper.java:137)
    at android.app.ActivityThread.main(ActivityThread.java:4424)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:511)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
    at dalvik.system.NativeStart.main(Native Method)
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
See point #1 in my previous answer. Your code cannot work.

It should look like this:
B4X:
For i = 1 to 1000
 Dim btn As Button
 ...'initialize
 BBCodeView1.Views.Put("b" & i, btn)
               str= str & $"${CRLF}${CRLF}${name}${CRLF}${country}${CRLF}${status}
[url = "https://www.google.com"]View Result [/url][Alignment=right][View=b${i}/][/Alignment]"$
 
  • Like
Reactions: omo
Upvote 0

omo

Active Member
Licensed User
Longtime User
See point #1 in my previous answer. Your code cannot work.

It should look like this:
B4X:
For i = 1 to 1000
Dim btn As Button
...'initialize
BBCodeView1.Views.Put("b" & i, btn)
               str= str & $"${CRLF}${CRLF}${name}${CRLF}${country}${CRLF}${status}
[url = "https://www.google.com"]View Result [/url][Alignment=right][View=b${i}/][/Alignment]"$

Thank you Erel, i am so grateful. I have already adapted it to my code. It worked well, i used sender to identify each button under button click event šŸ¤£
 
Upvote 0
Top