Cast Error With Firebaserecyclerviewadapter
Solution 1:
You should have really placed more of the error on your post. It would have shown where the issue was happening. However, I will try to make an educated guess after looking at he source for FirebaseRecyclerViewAdapter
.
The issue appears to be with the layout that you passes to the adapter, android.R.layout.simple_list_item_1
. The adapter expects a layout that is wrapped by a subclass of ViewGroup
, such as a LinearLayout
, FrameLayout
or some other type of Layout. android.R.layout.simple_list_item_1
is implemented like this:
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/text1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceListItemSmall"
android:gravity="center_vertical"
android:paddingStart="?android:attr/listPreferredItemPaddingStart"
android:paddingEnd="?android:attr/listPreferredItemPaddingEnd"
android:minHeight="?android:attr/listPreferredItemHeightSmall" />
As you can see, the TextView
is not wrapped inside of a Layout. The quickest way to fix the error would be to create your own layout, with a TextView
inside of a FrameLayout
like so:
<FrameLayoutxmlns:android="http://schemas.android.com/apk/res/android"android:layout_width="match_parent"android:layout_height="wrap_content"><TextViewandroid:id="@android:id/text1"android:layout_width="match_parent"android:layout_height="wrap_content"android:textAppearance="?android:attr/textAppearanceListItemSmall"android:gravity="center_vertical"android:paddingStart="?android:attr/listPreferredItemPaddingStart"android:paddingEnd="?android:attr/listPreferredItemPaddingEnd"android:minHeight="?android:attr/listPreferredItemHeightSmall" /></FrameLayout>
You would then pass the layout you created to the adapter. Lets call it my_simple_list_item_1.xml
, which you would pass to the adapter as R.layout.my_simple_list_item_1
.
Post a Comment for "Cast Error With Firebaserecyclerviewadapter"