Android Question [Solved] Find item in CustomListView

asales

Expert
Licensed User
Longtime User
I have a CustomListView, populating using data from sqlite database, with this information:
Type of Event - Date of Event
Labor Day - 2016-05-01
My Own Day - 2016-05-12
Independence Day - 2016-07-04
Christmas - 2016-12-25

I want to find the item that is equal or close to actual date.

Example:
Today is 2016-05-10.
How I can find and select the item "My Own Day - 2016-05-12" (more close to actual date) in CLV, after load the data from sqlite?

Thanks in advance for any tip.
 
1. Add the ticks value as the items Value parameter.
Code: Copy
clv.Add(MyPanel, 50dip, DateTime.DateParse(...))

2. Find the closest date:
Code: Copy
Dim distance As Long = 999999999999
Dim index As Int = -1
For i = 0 To clv.GetSize - 1 
 Dim eventTime As Long = clv.GetValue(i)
 Dim d As Long = Abs(DateTime.Now - eventTime)
 If d < distance Then 
  distance = d
  index = i
 End If
Next
'The index variable holds the index of the closest item
 
Upvote 0
Back
Top