I wanted to update my layout from
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="10dp"
android:textSize="16sp" >
</TextView>
To
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView
android:id="@+id/maintitle"
android:layout_width="fill_parent"
android:layout_height="50dp"
android:padding="10dp"
android:text="@string/choose_contact"
android:textSize="16sp" />
<TextView
android:id="@+id/contentlist"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="10dp"
android:textSize="16sp" />
</LinearLayout>
So I can have that header text. Now, I was using
setListAdapter(new ArrayAdapter<String>(this, R.layout.list_item, arraylist));
To send my data, but I’m now getting a “ArrayAdapter requires the resource ID to be a view”. So I’m trying to use a different constructor, namely
ArrayAdapter(Context context, int resource, int textViewResourceId, T[] objects)
to reference the specific ID of my textview, but I haven’t found out how to do so.
I thought it would be something along the lines of
R.layout.list_item.id_of_my_txtview
How do I reference the textview id to use this constructor?
thanks
Reference your TextView ID as any other View ID: R.id.id_of_the_view. Reference: XML Layouts – ID.
Code will look like this: