'Designer file "1": add custom listview = anchors left, top; layout (0, 20, 330, 480); divider size = 0; border width = 0
Sub Process_Globals
Private fx As JFX
Private xui As XUI
Private MainForm As Form
Private CustomListView1 As CustomListView
Private mIconFont, defaultFont As B4XFont
End Sub
Sub AppStart (Form1 As Form, Args() As String)
MainForm = Form1
MainForm.RootPane.LoadLayout("1") 'Load the layout file.
MainForm.Show
mIconFont = xui.CreateMaterialIcons(30)
defaultFont = xui.CreateDefaultFont(18)
CustomListView1.DefaultTextBackgroundColor = xui.Color_White
CustomListView1.sv.color = xui.Color_Transparent
CustomListView1.PressedColor = xui.Color_White
For i = 0 To 6
CustomListView1.Add(addRadioItem("Item " & i, 30), "")
Next
CustomListView1.sv.SetLayoutAnimated(0, 0, 0, CustomListView1.GetBase.Width, CustomListView1.Size * CustomListView1.GetPanel(0).Height)
End Sub
Sub addRadioItem(text As String, h As Int) As B4XView
Dim h2 As Int = h / 2
Dim h3 As Int = 2 * h / 3
Dim w As Int = CustomListView1.GetBase.Width
Dim offset As Int = h + h3 + 5dip
Dim pnl As B4XView = xui.CreatePanel("")
pnl.SetLayoutAnimated(0, 0, 0, w, 1.8 * h)
pnl.Color = xui.Color_White
Dim mark As B4XView = makeMark
turnMarkOff(pnl, mark)
pnl.AddView(mark, h3, h2, h, h)
Dim caption As Label: caption.Initialize("")
Dim xcaption As B4XView = caption
xcaption.font = defaultFont
xcaption.Text = text
pnl.AddView(caption, offset, h2, w - offset, h)
Return pnl
End Sub
Sub CustomListView1_ItemClick (Index As Int, Value As Object)
For j = 0 To 6
Dim pnl As B4XView = CustomListView1.GetPanel(j)
Dim mark As B4XView = pnl.GetView(0)
If j = Index Then
If pnl.Tag Then turnMarkOff(pnl, mark) Else turnMarkOn(pnl, mark)
Else
turnMarkOff(pnl, mark)
End If
Next
End Sub
Sub makeMark As B4XView
Dim nativeMark As Label: nativeMark.Initialize("")
Dim mark As B4XView = nativeMark
mark.Font = mIconFont
Return mark
End Sub
Sub turnMarkOn(pnl As B4XView, mark As B4XView)
mark.Text = Chr(0xE8DC)
mark.TextColor = xui.Color_RGB(0, 160, 0)
pnl.Tag = True
End Sub
Sub turnMarkOff(pnl As B4XView, mark As B4XView)
mark.Text = Chr(0xE8DB)
mark.TextColor = xui.Color_RGB(180, 180, 255)
pnl.Tag = False
End Sub