B4J Question Simple Custom listview example?

aidymp

Well-Known Member
Licensed User
Longtime User
Hi I want to add images to a list view in B4J, looking in the forum I cannot see one example of doing this simply, I have seen the example that loads images from a webpage, and does what I want, but I just add local images and 2 lines of text, the examples seem too busy for me to see the actual basic code to do this!

I was hoping I could use a sub like so

B4X:
Sub addline(image as image, line1 as string, line2 as string)
...
End sub
Thanks

Aidy
 

inakigarm

Well-Known Member
Licensed User
Longtime User
You can design a layout with Designer(you can do it also coding): a Panel with an imageview and two labels, load into a panel, and populate the listview with the panels

At this example (extracted from one of my applications), you have one Webview and two labels

B4X:
Private Lstgroupsel as Listview
Private Wbvgroup as Webview
Private lstpicartistmed as List
Private Lbltxtgrup, Lbltxtsong as Label

For i=0 To lstartist.Size-1
                    
       Dim p As AnchorPane
       p.Initialize("")
       p.LoadLayout("lstlaygroup")       'Load the layout designed at Internal Designer
                   
       Lbltxtgrup.Text = "artist " & i
       Lbltxtsong.Text = "song " & i
       Wbvgroup.LoadUrl(lstpicartistmed.Get(i))     'Load the Url at item i of the list lstpicartistmed
       Wbvgroup.Style="-fx-effect: dropshadow(three-pass-box,rgba(0,0,0,0.8),15,.00,5,8);"
       Lstgroupsel.Items.Add(p)     'Add the panel to the listview
                   
Next
 
Upvote 0

aidymp

Well-Known Member
Licensed User
Longtime User
You can design a layout with Designer(you can do it also coding): a Panel with an imageview and two labels, load into a panel, and populate the listview with the panels

At this example (extracted from one of my applications), you have one Webview and two labels

B4X:
Private Lstgroupsel as Listview
Private Wbvgroup as Webview
Private lstpicartistmed as List
Private Lbltxtgrup, Lbltxtsong as Label

For i=0 To lstartist.Size-1
                  
       Dim p As AnchorPane
       p.Initialize("")
       p.LoadLayout("lstlaygroup")       'Load the layout designed at Internal Designer
                 
       Lbltxtgrup.Text = "artist " & i
       Lbltxtsong.Text = "song " & i
       Wbvgroup.LoadUrl(lstpicartistmed.Get(i))     'Load the Url at item i of the list lstpicartistmed
       Wbvgroup.Style="-fx-effect: dropshadow(three-pass-box,rgba(0,0,0,0.8),15,.00,5,8);"
       Lstgroupsel.Items.Add(p)     'Add the panel to the listview
                 
Next

Thank you, So you design one element of the list view, and then for each item you add, it adds a duplicate of the panel you created?

-- EDIT This maybe where I am getting confused, as the examples all use forms created with the old version of B4J that uses SceneBuilder, and I dont have this installed as I don't use it! So was just expecting the examples to work when i copied subs from them to my own program!

Thanks again

Aidy
 
Upvote 0

inakigarm

Well-Known Member
Licensed User
Longtime User
Each element of the listview is a panel (each with an Webview with different URL, and two labels, each with different text on each panel)

See the example attached
 

Attachments

  • jlwpaneexample.zip
    43.7 KB · Views: 461
Upvote 0

aidymp

Well-Known Member
Licensed User
Longtime User
Each element of the listview is a panel (each with an Webview with different URL, and two labels, each with different text on each panel)

See the example attached

Thank you so much, that is excellent, and I can seen that you design the list view element in the designer! which as I was not using scenebuilder and either missed, or it wasn't made clear in the documentation that you do it that way, so i was using code with no actual form lol! Thanks again you are a credit to the community.

Aidy
 
Upvote 0
Top