B4J Question images in BBlistview - there must be an easier way

johnmie

Active Member
Licensed User
Longtime User
Hello everybody,
my soon to be released healthy nutrition app sports a help or showcase file which is essentially an expandable CLV list which I adore (thanks, Erel) with BBlistviewitems (Klaus showed me how) inside.
So far no problem except when it comes to tables. Some cells are multiline, others use diffrent fonts etc.

Having not found anywhere a viable example, I created a workaround with labels for each cell in a row, placed on a canvas, took a snapshot and save the to disk like this:
Builds each complex table row:
   Q.xRow = Q.xRow+ 1
    Dim pnl As B4XView = xui.CreatePanel("")
    pnl.LoadLayout("Pane23")
    pnl.Width = maxWidth-Wmin
    pnl.Height = maxHeight
    Dim bmx As B4XBitmap = Pane22.Snapshot
    Dim Oname As String = $"xpx_${Q.nRow}"$
    Dim Ostream As OutputStream
    Ostream = File.OpenOutput(Q.tempPath, Oname, False)
    bmx.WriteToStream(Ostream, 100, "PNG")
    Ostream.Close
    Q.currentPnlPix = Oname
    Dim Out As String =$"[Alignment=Center][img dir=${Q.TempPath} FileName="${Oname}" width=${bmx.Width}/][/Alignment]"$
    Q.nRow=Q.nRow+1
    Return Out

This is quite cumbersome and takes a lot of time (1-2 seconds per table). Ideally I'd like to put the row BMX directly into an internal cache and use it in the bblistitem Out String ([View=... instead of [img dir=... and FileName=...).

But how, any ideas?

Thanks for your help,
john m.
 

Attachments

  • home-fries_DE.jpg
    home-fries_DE.jpg
    49.4 KB · Views: 136

johnmie

Active Member
Licensed User
Longtime User
Adding a view to BCTextEngine is simple.

The tutorial demonstrates it: https://www.b4x.com/android/forum/t...-bbcode-parser-rich-text-view.106207/#content

B4X:
BBListItem1.Views.Put("pnl1", pnl)

And then add "[View=pnl1/]" in your bbcode.
This is obviously the first thing I tried since I have used it successfully in BBCodeView, BBListItem is not mentioned in the tutorial (at least not in the version I have studied.
Naïv as I am, I did at first not realize that BBListItem is just one line and is re-initialized with each iteration (i.e. each row in the table)

As the whole set (of all expandable items) is created at once when the file is loaded and before topics can be expanded, I was looking for a way to store these views in a cache but failed. How could a cache be addressed like a directory and an image as a bitmap to avoid the workaround via *.jpg or *.png file)?

johnmie
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Example of adding views:
B4X:
Private Sub B4XPage_Created (Root1 As B4XView)
    Root = Root1
    If Root.Width = 0 Then
        Wait For B4XPage_Resize (Width As Int, Height As Int)
    End If
    Root.LoadLayout("MainPage")
    TextEngine.Initialize(Root)
    For i = 1 To 30
        Dim pnl As B4XView = xui.CreatePanel("")
        pnl.SetLayoutAnimated(0, 0, 0, CustomListView1.AsView.Width, 100dip)
        pnl.LoadLayout("Item")
        Dim BB As BBListItem = pnl.GetView(BBListItemIndexInItems).Tag 
        Dim orig As Int = BB.mBase.Height
        BB.TextEngine = TextEngine
        Dim btn As Button '<-------
        btn.Initialize("btn")
        btn.Text = "button #" & i
        btn.SetLayoutAnimated(0, 0, 0, 100dip, 50dip)
        BB.Views.Put("btn1", btn)
        BB.Text = CreateItemText(i)
        pnl.SetLayoutAnimated(0, 0, 0, pnl.Width, Max(pnl.Height, pnl.Height + BB.mBase.Height - orig))
        CustomListView1.Add(pnl, "")
    Next
    CustomListView1_ScrollChanged(0)
End Sub

Private Sub CreateItemText(index As Int) As String
    Dim sb As StringBuilder
    sb.Initialize
    sb.Append($"[alignment=center][b]Item #${index}[/b][/alignment]
[view=btn1/]"$)'<-------------
    For i = 1 To Rnd(1, 20)
        sb.Append(CRLF).Append($"[u]Line ${i}[/u]: [color=red]alksd[/color] [url="https://www.b4x.com"]jalksd jklasd[/url] kalsd "$)
    Next
    Return sb.ToString
End Sub

1735198206724.png
 
Upvote 0
Top