Merged code - now the program shows both titles and dates in a nice layout.

This commit is contained in:
Robert Kolner committed 2011-09-14 19:43:21 +02:00
commit 00bea7f3ef
4 files changed
+65 -27

No files matched your search

+8 -1
View File
@@ -6,6 +6,13 @@
<TextView android:id="@+id/event_list_row_text"
android:layout_height="wrap_content"
android:layout_width="match_parent" />
android:layout_width="match_parent"
android:layout_alignParentTop="true" />
<TextView android:id="@+id/event_list_row_date"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@id/event_list_row_text" />
</RelativeLayout>
@@ -21,4 +21,30 @@ public class DataHandler {
}
return null;
}
public Event[] populateList() {
return events.toArray(new Event[events.size()]);
}
public static 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;
}
}
+19 -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,16 @@ public class Event {
this.location = location;
this.category = category;
}
public String toString() {
return this.title;
}
public String getDateString() {
String date = this.date;
String month = date.substring(5, 7);
String day = date.substring(8, 10);
return day + ". " + DataHandler.toMonth(month);
}
}
@@ -13,6 +13,7 @@ import android.widget.TextView;
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;
@@ -51,8 +52,9 @@ public class ProgramList extends ListActivity {
}
protected ListAdapter createAdapter() {
String[] vals = populateList();
ListAdapter adapter = new ArrayAdapter<String>(this, R.layout.event_list_row, R.id.event_list_row_text, vals) {
Event[] events = dh.populateList();
ListAdapter adapter = new ArrayAdapter<Event>(this, R.layout.event_list_row, R.id.event_list_row_text, events) {
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View row;
@@ -64,28 +66,19 @@ public class ProgramList extends ListActivity {
row = convertView;
}
TextView tv = (TextView) row.findViewById(R.id.event_list_row_text);
tv.setText(getItem(position));
Event e = getItem(position);
TextView titleView = (TextView) row.findViewById(R.id.event_list_row_text);
titleView.setText(e.title);
TextView dateView = (TextView) row.findViewById(R.id.event_list_row_date);
dateView.setText(e.getDateString());
return row;
}
};
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;
}
}