Why is it saying 'RecyclerView has no LayoutManager' when there is one. Please see details

无人久伴 提交于 2019-12-01 21:00:38

Remove the child elements from your RecyclerView in your fragment_accept_a_request layout.

You add children to your recycler views with the adapter, not via nested XML elements.

The problem is that when the layout inflation tries to add those children you've declared in your XML the parent RecyclerView is not yet fully configured to have children.

I got it!

The problem was in two files.

First problem as stated by laalto was in fragment_accept_a_request.xml. Removing the XML elements from recyclerView & placing it below it but in the same parent layout did the job.

Second problem was in AcceptARequest.java. Here I was declaring two RecyclerView one for initialiseData() method & another for declaring the recyclerView.

The changes I made in fragment_accept_a_request.xml is:

<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="wrap_content"
                android:paddingLeft="@dimen/activity_horizontal_margin"
                android:paddingRight="@dimen/activity_horizontal_margin"
                android:paddingTop="@dimen/activity_vertical_margin"
                android:paddingBottom="@dimen/activity_vertical_margin"
                xmlns:app="http://schemas.android.com/apk/res-auto"
                tools:context="com.abc.xyz.AcceptARequest">

    <android.support.v7.widget.RecyclerView
        android:id="@+id/accept_request_list"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@android:color/white"
        app:layout_behavior="@string/appbar_scrolling_view_behavior">

    </android.support.v7.widget.RecyclerView>

    <android.support.v7.widget.CardView
        android:id="@+id/card_accept_request"
        android:layout_width="match_parent"
        android:layout_height="@dimen/card_accept_request"
        app:cardElevation="2dp"
        app:cardUseCompatPadding="true"
        app:contentPadding="10dp">

        <!--<ImageView
            android:id="@+id/pic_accept"
            android:layout_width="match_parent"
            android:layout_height="@dimen/pic_dimen_accept"
            android:layout_gravity="center_horizontal|center_vertical"
            android:layout_alignParentTop="true"/> -->

        <TextView
            android:id="@+id/pic_tag"
            android:layout_width="match_parent"
            android:layout_height="@dimen/pic_dimen_accept"
            android:text="@string/image_view_tag_accept"
            android:gravity="center_horizontal|center_vertical"/>

    </android.support.v7.widget.CardView>

</RelativeLayout>
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!