I'm trying to access the Android Calender & get display all events
within a week of the current time using a ListView. Here's the code.
The issue is that I'm only getting events before the current date.
Even if I print out all events to the log, I only see those before the
current date. How do I resolve this issue?
ContentResolver contentResolver = this.getContentResolver();
// Fetch a list of all calendars synced with the device, their
display names and whether the
// user has them selected for display.
final Cursor cursor =
contentResolver.query(Uri.parse("content://
com.android.calendar/calendars"),
(new String[] { "_id", "displayName",
"selected=1" }), null, null,
null);
// For a full list of available columns see
http://tinyurl.com/yfbg76w
HashSet<String> calendarIds = new HashSet<String>();
while (cursor.moveToNext()) {
final String _id = cursor.getString(0);
final String displayName = cursor.getString(1);
final Boolean selected =
!cursor.getString(2).equals("0");
Log.d("Calendars","Id: " + _id + " Display Name: " +
displayName +
" Selected: " + selected);
calendarIds.add(_id);
}
adapter=new
ArrayAdapter<String>(this,android.R.layout.simple_list_item_1,
listItems);
setListAdapter(adapter);
// For each calendar, display all the events from the previous
week
to the end of next week.
for (String id : calendarIds) {
Cursor eventCursor =
contentResolver.query(builder.build(),
new String[] { "title", "dtstart",
"dtend"}, id,
null, null);
// For a full list of available columns see
http://tinyurl.com/yfbg76w
while (eventCursor.moveToNext()) {
String title = eventCursor.getString(0);
long start =
Long.parseLong(eventCursor.getString(1));
//long end =
Long.parseLong(eventCursor.getString(2));
//final Boolean allDay =
!eventCursor.getString(3).equals("0");
long currentTime = System.currentTimeMillis();
Log.d("Current Time", new
Date(currentTime).toString());
if(start - currentTime <=
DateUtils.WEEK_IN_MILLIS && start -
currentTime >=0){
Date st = new Date(start);
// Date en = new Date(end);
Log.d("Date Test", "Title: " +title
+'\n'+"Start:
"+st.toString());
/* Find Tablelayout defined in main.xml
*/
listItems.add("Title: " +title
+'\n'+"Start: "+st.toString());
}
}
}
adapter.notifyDataSetChanged();
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en