I\'m trying to add an ImageView to a preference fragment in order to show a preview of a color setting. I\'m accessing the instance of the imageview via the onCreateView met
When you create a custom layot for a PreferenceActivity or a PreferenceFragment you must supply a ListView with id android.R.id.list where the Preferences go to.
<LinearLayout 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"
android:orientation="vertical" >
<ImageView
android:id="@+id/color_preview"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_marginTop="5dp"
android:background="#aaaaaa" />
<ListView
android:id="@android:id/list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="5dp" />
</LinearLayout>
I had this problem today as well. It stemmed from using the Android Tutorials here: http://developer.android.com/guide/topics/ui/settings.html#Fragment
Basically, I found the problem came from using the preferences.xml file:
addPreferencesFromResource(R.xml.preferences);
Once I commented this out, the error went away and my activity started showing, although unpopulated by preferences. I'll try to hunt this down and follow up here.
I hope this helped so far! The exception thrown is not very helpful.
I had the same problem, and the solution was to ensure that I was importing the correct Fragment library:
import android.app.Fragment;
(not the version from the support library)