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.


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

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: 34
Last edited:
Cookies are required to use this site. You must accept them to continue using the site. Learn more…