Android Code Snippet [B4X] Create List Item (with checkbox, imageview and 2 labels)

Extract the zip files into B4X additional folder. It contains Snippets and Views folders.
Make sure XUI Views library is selected. chkItem is a Switch in B4i.

Tutorial: https://www.b4x.com/android/forum/threads/b4x-code-snippets.152450/

First, add the layout file.
Right click the Files Manager and Add Files (browse to Views folder) then choose the platform specific layout.
1732097611456.png


Type Code and use arrow key to select the snippet.
Press Enter to confirm.
1732096679902.png

Output code:
B4X:
Private Sub CreateListItem (FirstLine As String, SecondLine As String, Width As Int, Height As Int) As B4XView
    Dim p As B4XView = xui.CreatePanel("")
    p.LoadLayout("ListItem")
    p.SetLayoutAnimated(0, 0, 0, Width, Height)
    imgItem.Bitmap = xui.LoadBitmapResize(File.DirAssets, "icon.png", 40dip, 40dip, True)
    lblFirstLine.Text = FirstLine
    lblSecondLine.Text = SecondLine
    Return p
End Sub
Note: icon.png is not attached.

Usage:
B4X:
CustomListView1.Add(CreateListItem("First Line", "Second Line", CustomListView1.AsView.Width, 120dip), 1)
 

Attachments

  • B4X.zip
    5.5 KB · Views: 15
Last edited:
Top