Android Cursor Issue with Calendar -
i'm trying make app tells me whats next meeting in calendar. did place cursor on last event , start getting start times until 1 that's smaller right now, then, use previous item. works fine when creating events in order not if create event in between. here example:
lets set time 13:00 hours have events added before @ 15:00 (event 1), 16:00 (event 2), 17:00 (event 3) cursor goes read start time of event 3. since start time bigger right now, goes previous one, event 2 since start time bigger, goes previous one, event 1. since start time bigger, goes previous one, event yesterday. since start smaller, gets id, title , start , end times event 1.
that works fine, problem is, when add @ lets 14:00 (event 0) after added others first, events 1, 2 , 3 wont event 0, keeps information of event 1.
how can make correctly made?
here code
big in advance
regards
public class calendarinfo extends activity { int idnumber = 0; private cursor mcursor = null; private static final string[] cols = new string[] { calendarcontract.events.title, calendarcontract.events.dtstart, calendarcontract.events.dtend, calendarcontract.events._id}; protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.calendar_info); button buttonchange999 = (button) findviewbyid(r.id.button999); buttonchange999.setonclicklistener(new view.onclicklistener() { public void onclick(view v) { mcursor = getcontentresolver().query( calendarcontract.events.content_uri, cols, null, null, null); mcursor.movetolast(); calendar cal = calendar.getinstance(); long currenttimestart = cal.gettimeinmillis(); long ammountofdaypassed = currenttimestart/86400000; string title = "n/a"; long start = 9223372036854775806l; long end = 0l; int id = 0; string title2 = "n/a"; long start2 = 9223372036854775806l; long end2 = 0l; int id2 = 0; while(start>currenttimestart){ try { title = mcursor.getstring(0); start = mcursor.getlong(1); end = mcursor.getlong(2); id = mcursor.getint(3); } catch (exception e) { //ignore } if(start>currenttimestart){ title2 = title; start2 = start; end2 = end; id2 = id; } mcursor.movetoprevious(); } dateformat formatter01 = new simpledateformat("dd/mm/yyyy hh:mm:ss"); calendar calendar01 = calendar.getinstance(); calendar01.settimeinmillis(start2); string starttext = formatter01.format(calendar01.gettime()); dateformat formatter02 = new simpledateformat("dd/mm/yyyy hh:mm:ss"); calendar calendar02 = calendar.getinstance(); calendar02.settimeinmillis(end2); string endtext = formatter02.format(calendar02.gettime()); if(start2>currenttimestart && end2>currenttimestart){ settingstextview.settext("meeting: "+title2+"\n"+"at: "+starttext+"\n"+"until: "+endtext+"\n"+"id: "+id2); idnumber=id2; } else{ settingstextview.settext("no next meeting" + "\n" + "meeting: "+title2+"\n"+"at: "+starttext+"\n"+"until: "+endtext+"\n"+"id: "+id2); idnumber=id2; } } });
}
solved adding 1 if in line:
if(start>currenttimestart){ if(start<start2){ title2 = title; start2 = start; end2 = end; id2 = id; } }
Comments
Post a Comment