From: Petru Trimbitas Date: Mon, 10 Jun 2013 10:41:00 +0000 (+0300) Subject: ListView now displays the first event that isn't finished X-Git-Url: http://git.ieval.ro/?a=commitdiff_plain;h=bbab7d107a15806894f0450c0dc10e195aed5b30;p=unical.git ListView now displays the first event that isn't finished --- diff --git a/src/ro/ieval/unical/EventListActivity.java b/src/ro/ieval/unical/EventListActivity.java index 7379d59..cb2ee6d 100644 --- a/src/ro/ieval/unical/EventListActivity.java +++ b/src/ro/ieval/unical/EventListActivity.java @@ -2,6 +2,7 @@ package ro.ieval.unical; import java.util.Arrays; import java.util.Comparator; +import java.util.Date; import android.app.Activity; import android.content.Intent; @@ -24,10 +25,16 @@ public class EventListActivity extends Activity { 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; inew 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