在使用 B4A 中,我们需要实现 B4A 的高亮选中,但是自带的 listview 是没有这个的功能的,这里通过 listview 的 2 种添加模式,进行实现!
1.设置 listview 的属性
Dim lstview As ListView
lstview .Color = Colors.DarkGray
lstview .SingleLineLayout.Label.TextColor = Colors.White
lstview .TwoLinesLayout.Label.TextColor = Colors.Red
lstview .TwoLinesLayout.SecondLabel.TextColor = Colors.Green
2.我们在 listview 里面加入列表
Dim lst() As String = Array As String(“123”,”456”,”789”)
For ii = 0 To lst.length - 1
lstview.AddSingleLine(lst(ii-1))
Next
3.当我们点击 list 时会触发 event
Sub lstview_ItemClick (Position As Int, Value As Object)
4.我们需先 clear 所有列表
lstview.Clear
5.然后再重新加入列表,不过当 event 中的 Position 和 list 序号相同时,我们使用添加 2 行的方法
For ii = 0 To lst.length - 1
If(ii = Position ) Then
lstview.AddTwoLines("当前选择为" , lst(ii))
Else
lstview.AddSingleLine(lst(ii-1))
End If
Next
lstview.SetSelection(Position)
6.这样就实现了 list 的高亮