Android Question Unable to scroll BBCodeView with code

RB Smissaert

Well-Known Member
Licensed User
Longtime User
When showing a BBCodeView with a large amount of text (it shows an error log) I want it to scroll to a certain position.
For some reason it doesn't scroll and can't figure out why this is:

B4X:
    If iScrollPositionY > 0 Then
        Log("iScrollPositionY: " & iScrollPositionY)
        bbcvPrompt.sv.ScrollViewOffsetY = iScrollPositionY
        Log("bbcvPrompt.sv.ScrollViewOffsetY: " & bbcvPrompt.sv.ScrollViewOffsetY)
    End If

iScrollPositionY has the right value, but bbcvPrompt.sv.ScrollViewOffsetY remains at zero.

Any idea what the problem could be here?

RBS
 

RB Smissaert

Well-Known Member
Licensed User
Longtime User
When showing a BBCodeView with a large amount of text (it shows an error log) I want it to scroll to a certain position.
For some reason it doesn't scroll and can't figure out why this is:

B4X:
    If iScrollPositionY > 0 Then
        Log("iScrollPositionY: " & iScrollPositionY)
        bbcvPrompt.sv.ScrollViewOffsetY = iScrollPositionY
        Log("bbcvPrompt.sv.ScrollViewOffsetY: " & bbcvPrompt.sv.ScrollViewOffsetY)
    End If

iScrollPositionY has the right value, but bbcvPrompt.sv.ScrollViewOffsetY remains at zero.

Any idea what the problem could be here?

RBS
Still not figured this out and here the relevant code dealing with this BBCodeView:

B4X:
    If tDP.bPrompt Then 'tDP is a type that will have all the needed dialog properties
        
        Dim TextEngine As BCTextEngine
        
        TextEngine.Initialize(Parent) 'Parent will be root of a B4XPage
        bbcvPrompt.TextEngine = TextEngine
        
        'this is needed to show the large error log, otherwise will get error:
        'java.lang.OutOfMemoryError: Failed to allocate a 240055984 byte allocation with 25165824 free bytes
        'and 194MB until OOM, target footprint 89390400, growth limit 268435456
        '---------------------------------------------------------------------------------------------------
        bbcvPrompt.LazyLoading = True 'but already set so in the designer
        
        If tDP.bPromptScroll Then
            bbcvPrompt.mBase.Height = tDP.iPromptHeight
            Log("bbcvPrompt.mBase.Height: " & bbcvPrompt.mBase.Height)  '23820
        Else
            bbcvPrompt.mBase.Height = tDP.iScrollViewHeight
        End If
        
        bbcvPrompt.sv.Height = tDP.iScrollViewHeight
        Log("bbcvPrompt.sv.Height: " & bbcvPrompt.sv.Height) '1311
        bbcvPrompt.mBase.Top = tDP.iPromptTop
        bbcvPrompt.mBase.Width = tDP.iScrollViewWidth 'this is same as tDP.iPromptWidth
        
        Dim rectPadding As B4XRect
        rectPadding.Initialize(arrPromptPadding(0), arrPromptPadding(1), arrPromptPadding(2), arrPromptPadding(3))
        bbcvPrompt.Padding = rectPadding
        
        '------------------------------------------------'
        'This is the way to set the BBCodeView background'
        '------------------------------------------------'
        bbcvPrompt.mBase.Color = iPromptColour
        bbcvPrompt.sv.Color = iPromptColour
        bbcvPrompt.sv.ScrollViewInnerPanel.Color = iPromptColour
        
        If tDP.bcsPrompt Then
            bbcvPrompt.Text = csPrompt 'this won't happen
        Else
            'bbcvPrompt.Text = strPrompt
            Dim rs As ResumableSub = SetBBCodeviewText(strPrompt) 'just for in case the problem was a timing issue
            Wait For (rs) Complete (bResult As Boolean)
            Log("bResult: " & bResult) 'True
        End If
        
        If iScrollPositionY > 0 Then
            Log("iScrollPositionY: " & iScrollPositionY) '8266
            bbcvPrompt.sv.ScrollViewOffsetY = iScrollPositionY
            Log("bbcvPrompt.sv.ScrollViewOffsetY: " & bbcvPrompt.sv.ScrollViewOffsetY) '0 (??)
        End If

Using this ResumableSub made no difference:

B4X:
Sub SetBBCodeviewText(strText As String) As ResumableSub
    bbcvPrompt.Text = strText
    Return True
End Sub

I logged all the relevant values and put these as comments in the above code.

RBS
 
Upvote 0

RB Smissaert

Well-Known Member
Licensed User
Longtime User
Actually, it should be:

B4X:
bbcvPrompt.mBase.Height = tDP.iScrollViewHeight

as this applies to the height of the visible control.
I think that this is different than for example a simple label added to a scrollview.

This does't alter the mentioned problem though.

RBS
 
Upvote 0

RB Smissaert

Well-Known Member
Licensed User
Longtime User
I was thinking of that, but in my particular situation it seems quite an inefficient way.
I have a list of error messages. They are concatenated and prepared to be shown in the BBCodeview:

B4X:
Sub ConcatenateListItems(lst As List, strSeparator As String, bAddIndex As Boolean, bClickableNumbers As Boolean) As String
    
    Dim i As Int
    Dim strResult As String
    Dim strURLStart As String
    Dim strURLEnd As String
    
    If bClickableNumbers Then
        strURLStart = "[url]"
        strURLEnd = "[/url]"
    End If
    
    If bAddIndex Then
        For i = 0 To lst.Size - 1
            If i = 0 Then
                If bClickableNumbers Then
                    'we need the [Plain] tag as otherwise will get an error with for example showing an error log with: create table ddd([ID] integer >> invalid tag [ID]
                    strResult = strURLStart & (i + 1) & ")  " & strURLEnd & "[Plain]" & lst.Get(i) & "[/Plain]"
                Else
                    strResult = strURLStart & (i + 1) & ")  " & strURLEnd & lst.Get(i)
                End If
            Else
                If bClickableNumbers Then
                    strResult = strResult & strSeparator & strURLStart & (i + 1) & ")  " & strURLEnd & "[Plain]" & lst.Get(i) & "[/Plain]"
                Else
                    strResult = strResult & strSeparator & strURLStart & (i + 1) & ")  " & strURLEnd & lst.Get(i)
                End If
            End If
        Next
    Else
        For i = 0 To lst.Size - 1
            If i = 0 Then
                strResult = lst.Get(i)
            Else
                strResult = strResult & strSeparator & lst.Get(i)
            End If
        Next
    End If
    
    Return strResult
    
End Sub

Then with a click on the URL there will be a dialog with options to deal with the particular error message.
One is to clear that message, so delete it from the list and re-save the list to KVS.
After having cleared the message I show the new list again in the same BBCodeview as there can be messages
near the cleared message that need clearing again. So I want when showing the new list I want the BBCodeview
to be scrolled to the position of the previously cleared message. As I have the value of this scroll position I want
to just use this to scroll to that same position again (in code, not manually).
So, I don't think I need anchors.

RBS
 
Upvote 0
Top