import java.util.Arrays;
import java.util.Comparator;
+import java.util.Date;
import android.app.Activity;
import android.content.Intent;
private void displayEvents() {
final Event events[]=Event.getAllEvents(getBaseContext());
final ListView lv = (ListView) findViewById(R.id.eventlist);
+
Arrays.sort(events,new EventComparator());
+ int idx=-1;//index of the first event to be displayed
+ for(int i=0; i<events.length; ++i)
+ if(idx==-1 && events[i].dtend>new Date().getTime()) idx=i;
+ if(idx==-1) idx=0;
final EventAdapter adapter = new EventAdapter(this, events);
lv.setAdapter(adapter);
+ lv.setSelectionFromTop(idx, 0);
lv.setOnItemClickListener(new OnItemClickListener() {
@Override