Changed program list ArrayAdapter to show rows using a layout defined in xml files instead of simple TextView

This commit is contained in:
Robert Kolner committed 2011-09-14 19:25:44 +02:00
1 parent de3881aca7
commit 5471aae9ff
3 files changed
+40 -1

No files matched your search

+11
View File
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView android:id="@+id/event_list_row_text"
android:layout_height="wrap_content"
android:layout_width="match_parent" />
</RelativeLayout>
+8
View File
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
</RelativeLayout>
@@ -4,9 +4,12 @@ import org.w3c.dom.NodeList;
import android.app.ListActivity;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ListAdapter;
import android.widget.TextView;
import android.widget.Toast;
import com.studentersamfundet.app.DataHandler;
@@ -49,7 +52,24 @@ 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);
ListAdapter adapter = new ArrayAdapter<String>(this, R.layout.event_list_row, R.id.event_list_row_text, vals) {
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View row;
if (null == convertView) {
LayoutInflater inflater = getLayoutInflater();
row = inflater.inflate(R.layout.event_list_row, null);
} else {
row = convertView;
}
TextView tv = (TextView) row.findViewById(R.id.event_list_row_text);
tv.setText(getItem(position));
return row;
}
};
return adapter;
}