List of events displays date and title.

This commit is contained in:
Lars Jansøn Engvik committed 2011-09-14 19:21:16 +02:00
1 parent 9c16bbfa57
commit 9e2995bdf0
3 files changed
+52 -24

No files matched your search

@@ -21,4 +21,30 @@ public class DataHandler {
}
return null;
}
public Event[] populateList() {
return events.toArray(new Event[events.size()]);
}
public String toMonth(String m) {
int monthInt = Integer.parseInt(m);
String monthString;
switch (monthInt) {
case 1: monthString = "Jan"; break;
case 2: monthString = "Feb"; break;
case 3: monthString = "Mar"; break;
case 4: monthString = "Apr"; break;
case 5: monthString = "Mai"; break;
case 6: monthString = "Jun"; break;
case 7: monthString = "Jul"; break;
case 8: monthString = "Aug"; break;
case 9: monthString = "Sep"; break;
case 10: monthString = "Okt"; break;
case 11: monthString = "Nov"; break;
case 12: monthString = "Des"; break;
default: monthString = "NA"; break;
}
return monthString;
}
}
+11 -7
View File
@@ -1,14 +1,14 @@
package com.studentersamfundet.app;
public class Event {
int id;
String title;
String description;
String date;
String location;
String category;
public int id;
public String title;
public String description;
public String date;
public String location;
public String category;
Event(int id, String title, String description, String date, String location, String category) {
public Event(int id, String title, String description, String date, String location, String category) {
this.id = id;
this.title = title;
this.description = description;
@@ -16,4 +16,8 @@ public class Event {
this.location = location;
this.category = category;
}
public String toString() {
return this.title;
}
}
@@ -9,6 +9,7 @@ import android.widget.ListAdapter;
import android.widget.Toast;
import com.studentersamfundet.app.DataHandler;
import com.studentersamfundet.app.Event;
import com.studentersamfundet.app.FeedFetcher;
import com.studentersamfundet.app.R;
import com.studentersamfundet.app.XmlParser;
@@ -47,24 +48,21 @@ public class ProgramList extends ListActivity {
}
protected ListAdapter createAdapter() {
String[] vals = populateList();
ListAdapter adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, vals);
Event[] events = dh.populateList();
String[] titles = new String[events.length];
for (int i = 0; i < events.length; i++) {
Event e = events[i];
String date = e.date;
String month = date.substring(5, 7);
String day = date.substring(8, 10);
titles[i] = day + ". " + dh.toMonth(month) + ": " + e.title;
}
// TODO: Lag en fin liste med litt mer informasjon og slik.
ListAdapter adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, titles);
return adapter;
}
public String[] populateList() {
String[] val = new String[10];
val[0] = "test!";
val[1] = "test2";
val[2] = "test3";
val[3] = "test3";
val[4] = "test3";
val[5] = "test3";
val[6] = "test3";
val[7] = "test3";
val[8] = "test3";
val[9] = "test3";
return val;
}
}