I’m trying to use an ArrayAdapter in a ListActivity:
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.id.text1, new String[] { "a", "b"});
setListAdapter(adapter);
This is the layout:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TextView
android:id="@id/android:text1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10" />
<ListView
android:id="@id/android:list"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="false"
android:layout_below="@id/android:text1" >
</ListView>
</RelativeLayout>
None of the solutions I found on StackOverflow seems to work. I’m using API 10. Can you help please?
Define a layout for the rows of your ListView, and call it, for example,
simple_list_item_1(create the filesimple_list_item_1.xmlin the folderres/layout). Put yourTextViewinto this layout:and then create your ArrayAdapter like this:
Here you’ll find a detailed explanation about Lists and Adapters.