I'm adding a textview as a header to a listview, in a Xamarin Android app. Following the instructions in ericosg's answer to this SO question, I put the textview in a separate axml file, and then tried to add it as a header to my list view.
Running the app gets the following error at the line where the activity tries to inflate the textview:
[MonoDroid] UNHANDLED EXCEPTION:
[MonoDroid] Android.Content.Res.Resources+NotFoundException: Exception of type 'Android.Content.Res.Resources+NotFoundException' was thrown.
.
.
.
[MonoDroid] --- End of managed exception stack trace ---
[MonoDroid] android.content.res.Resources$NotFoundException: Resource ID #0x7f050006 type #0x12 is not valid
[MonoDroid] at android.content.res.Resources.loadXmlResourceParser(Resources.java:2250)
etc.
Here is my code:
In the Activity .cs file:
myListView = FindViewById<ListView>(MyApp.Resource.Id.MyList);
Android.Views.View myHeader =
this.LayoutInflater.Inflate(MyApp.Resource.Id.QuestionText, myListView);
myListView.AddHeaderView(myHeader);
ListView definition:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ListView
android:id="@+id/MyList"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1" />
</RelativeLayout>
Header definition:
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/QuestionText"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:drawableTop="@+id/MyImage" />