I'm trying to create a simple calendar with a ListView that includes dates from 01/01/2014 to 31/12/2014. In each row there is the date and name of day. I would like to highlight Sundays with a different background or font color but I can not do it, Can anyone help me please?
B4X:
Sub Globals
Dim ListView1 As ListView
DateTime.DateFormat = "dd/MM/yyyy"
Dim n As Int = 0
Dim Item As String
Dim Oggi As Long = DateTime.Now
Dim OggiS As String = DateTime.date(Oggi)
Dim Gt As Long
Dim Gs As String
Dim GiornoL As Long ' giorno della settimana (Lun, Mar...) in Tick
Dim GiornoS As String ' giorno della settimana (Lun, Mar...) in string
Dim G As Int = -1
End Sub
Sub Activity_Create(FirstTime As Boolean)
ListView1.Initialize("ListView1")
Dim GD As GradientDrawable
GD.Initialize("TR_BL", Array As Int(Colors.White, Colors.White))
Activity.Background = GD
ListView1.ScrollingBackgroundColor = Colors.Transparent
'Dim Bitmap1 As Bitmap
'Bitmap1.Initialize(File.DirAssets, "button.gif")
'Dim strDate1 As String= "01/01/2014" ' si imposta la data come stringa
Dim PrimoGiorno As Long=DateTime.DateParse("01/01/2014") ' si ricavano i ticks
'Gt =DateTime.Add(PrimoGiorno,0,0,1) ' si aggiunge un giorno sempre in ticks (millisecondi)
For i = 1 To 365
Gs = DateTime.Date(DateTime.Add(PrimoGiorno,0,0,G+i)) 'data in string
Gt = DateTime.DateParse(Gs) ' data in Tick
GiornoL = DateTime.GetDayOfWeek(Gt)
If GiornoL = 1 Then GiornoS = "Sun"
If GiornoL = 2 Then GiornoS = "Mon"
If GiornoL = 3 Then GiornoS = "Tue"
If GiornoL = 4 Then GiornoS = "Wed"
If GiornoL = 5 Then GiornoS = "Thu"
If GiornoL = 6 Then GiornoS = "Fri"
If GiornoL = 7 Then GiornoS = "Sat"
If GiornoS = "Sat" OR GiornoS = "Sun" Then
ListView1.TwoLinesLayout.ItemHeight = 80dip
ListView1.TwoLinesLayout.Label.TextSize = 16
ListView1.TwoLinesLayout.Label.TextColor = Colors.red
ListView1.TwoLinesLayout.Label.Gravity = Gravity.LEFT
ListView1.TwoLinesLayout.SecondLabel.TextSize = 16
ListView1.TwoLinesLayout.SecondLabel.TextColor=Colors.magenta
Else
ListView1.TwoLinesLayout.ItemHeight = 80dip
ListView1.TwoLinesLayout.Label.TextSize = 16
ListView1.TwoLinesLayout.Label.TextColor = Colors.Blue
ListView1.TwoLinesLayout.Label.Gravity = Gravity.LEFT
ListView1.TwoLinesLayout.SecondLabel.TextSize = 16
ListView1.TwoLinesLayout.SecondLabel.TextColor=Colors.DarkGray
End If
ListView1.AddTwoLines(Gs, GiornoS) ' riempie con tutte le date la ListView
Next
ListView1.FastScrollEnabled = True
Activity.AddView(ListView1, 0, 0, 100%x, 100%y)
For x = 1 To 365 ' ciclo per selezionare il giorno di oggi.
Item = ListView1.GetItem(x)
If Item= OggiS Then
n= n+x
ListView1.SetSelection(n)
Return
End If
Next
End Sub