I am populating a ListView from a SQLite table.
The ListView is a simple Diary application and has 24 items in the ListView.
(0 = Midnight ---- 23 = 11:00pm)
First I check if there are records in the table.
If there are NO records (Curs.RowCount = 0) I populate the ListView with text (MyDiaryTime) and a bitmap.
If there are records, I populate the ListView with the records from the table where eventdate = '"& MyDiaryDate &". The code should cycle through all the records and display the record at the correct position (MyEventTime = Curs.GetString("eventtime") which ==(i).
I am overlooking something, but can't find what I am doing incorrectly.
However, in the code below, I only get the first record from the table:
The ListView is a simple Diary application and has 24 items in the ListView.
(0 = Midnight ---- 23 = 11:00pm)
First I check if there are records in the table.
If there are NO records (Curs.RowCount = 0) I populate the ListView with text (MyDiaryTime) and a bitmap.
If there are records, I populate the ListView with the records from the table where eventdate = '"& MyDiaryDate &". The code should cycle through all the records and display the record at the correct position (MyEventTime = Curs.GetString("eventtime") which ==(i).
I am overlooking something, but can't find what I am doing incorrectly.
B4X:
Sub LoadHours(Date As Long)
DateTime.DateFormat = "dd/MM/yyyy"
MyDiaryDate=DateTime.date(Date)
lvHours.clear
Dim Curs As Cursor
Curs = SQL0.ExecQuery("SELECT * FROM diary WHERE eventdate = '"& MyDiaryDate &"'")' AND BookType= '"& MyBookType &"'")
If Curs.RowCount = 0 Then
For i=0 To 23
Dim MyAmPm As String
If i = 0 Then MyAmPm = "Midnight"
If i = 12 Then MyAmPm = "Noon"
If i >= 1 And i <= 11 Then MyAmPm = "am"
If i >= 13 And i <= 23 Then MyAmPm = "pm"
MyDiaryTime = i & ":00 " & MyAmPm
lvHours.TwoLinesAndBitmap.ItemHeight = 70dip
lvHours.TwoLinesAndBitmap.ImageView.Height = 65dip
lvHours.TwoLinesAndBitmap.ImageView.Width = 65dip
lvHours.TwoLinesAndBitmap.Label.TextColor=Colors.DarkGray
lvHours.TwoLinesAndBitmap.Label.TextSize = 15
lvHours.TwoLinesAndBitmap.Label.Left = (((lvHours.TwoLinesAndBitmap.ImageView.Left) + (lvHours.TwoLinesAndBitmap.ImageView.Width)) + 5dip)
lvHours.AddTwoLinesAndBitmap2(MyDiaryTime, (" " & "EventDetail") , LoadBitmap(File.DirAssets, i & ".png"),MyDiaryTime)
Next
Else
For i=0 To Curs.RowCount-1
Curs.Position=i
Dim MyEventTime As Int
Dim DiaryText As String
MyEventTime = Curs.GetString("eventtime")
DiaryText = Curs.GetString("eventdetail")
For i=0 To 23
Dim MyDiaryTime As String
Dim MyAmPm As String
If i = 0 Then MyAmPm = "Midnight"
If i = 12 Then MyAmPm = "Noon"
If i >= 1 And i <= 11 Then MyAmPm = "am"
If i >= 13 And i <= 23 Then MyAmPm = "pm"
MyDiaryTime = i & ":00 " & MyAmPm
lvHours.TwoLinesAndBitmap.ItemHeight = 70dip
lvHours.TwoLinesAndBitmap.ImageView.Height = 65dip
lvHours.TwoLinesAndBitmap.ImageView.Width = 65dip
lvHours.TwoLinesAndBitmap.Label.TextColor=Colors.DarkGray
lvHours.TwoLinesAndBitmap.Label.TextSize = 15
lvHours.TwoLinesAndBitmap.Label.Left = (((lvHours.TwoLinesAndBitmap.ImageView.Left) + (lvHours.TwoLinesAndBitmap.ImageView.Width)) + 5dip)
If i = MyEventTime Then
lvHours.AddTwoLinesAndBitmap2(MyDiaryTime, (" " & DiaryText) , LoadBitmap(File.DirAssets, i & ".png"),MyDiaryTime)
Else
lvHours.AddTwoLinesAndBitmap2(MyDiaryTime, ("") , LoadBitmap(File.DirAssets, i & ".png"),MyDiaryTime)
End If
Next
Next
Curs.Close
End If
End Sub