-
Displaying a List
Given the following object
Code:
public class EventList extends FrameLayout {
static final String[] EVENTS = new String[] {"Item one" , "Item two" , "Item three" ,"Item four", "Item five", "Item size"};
public EventList(Context context) {
super(context);
ListView eventList = (ListView)((Activity)context).findViewById(R.id.eventlistview);
List<HashMap<String,String>> eventStringList = new ArrayList<HashMap<String,String>>();
for(String event : EVENTS)
{
HashMap<String,String> map = new HashMap<String,String>();
map.put("Event", event);
eventStringList.add(map);
}
String[] from = new String[] {context.getString(R.string.event)};
int[] to = new int[] { R.id.itemforevent };
SimpleAdapter adapter = new SimpleAdapter(context, eventStringList, R.layout.eventlistlayout, from, to);
eventList.setAdapter(adapter);
}
}
With the following xml for eventlistlayout.xml
Code:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal"
>
<TextView
android:id="@+id/itemforevent"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:text="@string/event" />
</LinearLayout>
And the following main.xml
Code:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal" >
<WebView
android:id="@+id/webView1"
android:layout_width="821dp"
android:layout_height="match_parent"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true" />
<ListView
android:id="@+id/eventlistview"
android:layout_width="86dp"
android:layout_height="fill_parent"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_toLeftOf="@+id/webView1" >
</ListView>
</RelativeLayout>
And the Event list being called by
Code:
new EventList(this);
from the onCreate in the main activity why am I not seeing my list being populated