Android Question How to populate xListview from database and layout with multiple labels

mcqueccu

Well-Known Member
Licensed User
Longtime User
Hi, Looking at the xlistview example, I am trying to wrap my head around how to populate it with data from database, with layout that has like 5 labels.
Where do loop to load the data? is it in Sub xLv_PanelRequested(Index As Int)

Here is a sample of the data i need to load

B4X:
Dim parser As JSONParser
parser.Initialize(res)
Dim root As List = parser.NextArray
   
    For Each colroot As Map In root
        Dim noticetitle As String = colroot.Get("noticetitle")
        Dim noticemessage As String = colroot.Get("noticemessage")
        Dim noticedate As String = colroot.Get("noticedate")
        Dim id As String = colroot.Get("id")
        Dim noticeviews As String = colroot.Get("noticeviews")
        Dim noticeauthor As String = colroot.Get("noticeauthor")
    Next

xLv.NewItem(175dip,id)
 

KZero

Active Member
Licensed User
Longtime User
Define Type and List
B4X:
Type TItem(noticetitle As String,noticemessage As String,noticedate As String,id As String,noticeviews As String,noticeauthor As String)

Dim ListItems as List



B4X:
Dim parser As JSONParser
parser.Initialize(res)
Dim root As List = parser.NextArray

    For Each colroot As Map In root

       Dim Item as TItem
       Item.noticetitle=colroot.Get("noticetitle")
       Item.noticemessage=colroot.Get("noticemessage")
       Item.noticedate=colroot.Get("noticedate")
       Item.id = colroot.Get("id")
       Item.noticeviews = colroot.Get("noticeviews")
       Item.noticeauthor = colroot.Get("noticeauthor")
      
     ListItems.add(Item)
     xLv.NewItem(175dip, Item.id)
    Next
xLv.Reload



B4X:
Sub xLV_PanelRequested(Index As Int)
Dim p as Panel
p.initialize("")

P.loadLayout("YOUR ITEM LAYOUT")

Dim Item as TItem
Item = ListItems.get(Index)

Label1.text = Item.noticetitle
Label2.text = Item.noticemessage

......


End Sub

you can also use the Value object to store the TItem instead of creating ListItems
 
Last edited:
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…