Sub BuildTheSongListCustomListView
clvSongList.Clear
ButtonSongDetails.Visible = False
ButtonClearSong.Visible = False
intCurrentSongSelected = kvs.Get("CurrentSongSelected")
' Add 10 items to the list view.
'-------------------------------
For intIndex = 0 To 9
' typValues holds values from a custom type object that can be accessed from the values
' parameter of the ItemClick handler of this xCLV.
'--------------------------------------------------------------------------------------
Dim typValues As typSongsListItemValues
' Adding items to the list view requires a Panel created in code.
'----------------------------------------------------------------
Dim p As B4XView = xui.CreatePanel("")
' This is the size for the panel and it will be animated.
'--------------------------------------------------------
p.SetLayoutAnimated(0, 0, 0, PanelSongList.Width, 200dip)
p.LoadLayout("SongListCard")
' Populate the views with values from the database.
' Doing the replace here will make sure unchecked days will not be displayed in the list.
'----------------------------------------------------------------------------------------
LabelSongTitle.Text = kvs.Get("Song" & (intIndex + 1) & "Title")
LabelSchedule.Text = LTrim(kvs.Get("Song" & (intIndex + 1) & "Schedule"))
LabelSchedule.Text = LabelSchedule.Text.Replace("100 ", "")
LabelSchedule.Text = LabelSchedule.Text.Replace("200 ", "")
LabelSchedule.Text = LabelSchedule.Text.Replace("300 ", "")
LabelSchedule.Text = LabelSchedule.Text.Replace("400 ", "")
LabelSchedule.Text = LabelSchedule.Text.Replace("500 ", "")
LabelSchedule.Text = LabelSchedule.Text.Replace("600 ", "")
LabelSchedule.Text = LabelSchedule.Text.Replace("700 ", "")
LabelSchedule.Text = LTrim(LabelSchedule.Text)
LabelScheduleFromUntil.Text = _
kvs.Get("Song" & (intIndex + 1) & "ScheduleEnabledFrom") & " To " & _
kvs.Get("Song" & (intIndex + 1) & "ScheduleEnabledUntil")
If intIndex + 1 = _
kvs.Get("CurrentSongSelected") Then
If kvs.Get("Song" & (intIndex + 1) & "ScheduleIsEnabled") Then
ImageViewSongScheduleIsEnabled.Bitmap = _
LoadBitmap(File.DirAssets, "light-on-icon.png")
Else
ImageViewSongScheduleIsEnabled.Bitmap = _
LoadBitmap(File.DirAssets, "light-off-icon.png")
End If
ImageViewSongScheduleIsEnabled.Visible = True
ImageViewPlayPauseSong.Visible = True
Else
' These are not displayed when the list is built because they will only be displayed
' when the user selects a song later.
'-----------------------------------------------------------------------------------
ImageViewSongScheduleIsEnabled.Visible = False
ImageViewPlayPauseSong.Visible = False
End If
' This is where the item row is added to the list view.
' Each list item has a set of Type structure elements associated with it.
'------------------------------------------------------------------------
clvSongList.Add(p,typValues)
Next
' Force the last selected or schedulded song to be selected.
'-----------------------------------------------------------
If ServiceModule.blnScheduleIsPlayingSong Then
intCurrentSongSelected = ServiceModule.intSongNumberSelected
End If
Sleep(100)
clvSongList_ItemClick (intCurrentSongSelected - 1, "")
clvSongList.ScrollToItem(intCurrentSongSelected - 1)
End Sub