Two Recycler views inside nested scroll view

recyclerview inside nestedscrollview pagination
recyclerview onscrolllistener inside nestedscrollview
recyclerview inside nestedscrollview not recycling
recyclerview inside nestedscrollview performance
recyclerview inside recyclerview not scrolling
recyclerview inside nestedscrollview not scrolling smoothly
recyclerview inside scrollview
recyclerview inside viewpager not scrolling

I have a Nested Scroll view and inside this, I have a Linear Layout that includes two recycler views. Now the problem is that the first recycler view is not expanding up to its full extent. i.e. there are 5 items in the first recycler view list but it is only showing the first item if I put wrap content. This should expand up to 5 items because of wrap content but it is not working. If I fixed the height to 200DP or 300dp then it started to show more items up to that height. However, I want to show all the items of the first recycler view and then when I scroll it should start second recycler view items after the first recycler view items end.

My layout is:

<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.NestedScrollView
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fillViewport="true">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@color/colorPrimary"
        android:layout_marginTop="60dp"
        android:orientation="vertical">

        <com.sooryen.customview.CustomTextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_margin="@dimen/spacing_normal"
            android:text="@string/my_booking_latest_booking_lable"
            app:font="avenirltstd_medium" />

        <include layout="@layout/layout_divider" />

        <android.support.v7.widget.RecyclerView
            android:id="@+id/rv_ongoing_bookings"
            android:visibility="visible"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:layoutManager="android.support.v7.widget.LinearLayoutManager" />

        <com.sooryen.customview.CustomTextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:visibility="visible"
            android:layout_margin="@dimen/spacing_normal"
            android:text="@string/my_booking_past_booking_lable"
            app:font="avenirltstd_medium" />

        <include layout="@layout/layout_divider" />

        <android.support.v7.widget.RecyclerView
            android:id="@+id/rv_past_bookings"
            android:visibility="visible"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:nestedScrollingEnabled="false"
            android:layout_marginBottom="@dimen/spacing_extra_small"
            android:scrollbars="none"
            app:layoutManager="android.support.v7.widget.LinearLayoutManager" />
        <View
            android:layout_width="match_parent"
            android:layout_height="150dp" />
    </LinearLayout>
</android.support.v4.widget.NestedScrollView> 

Please Help. Where I did something wrong. I tried so many ways from internet but nothing is working. Here is a screenshot of the this screen

The LABEL latest bookings has 5 items but it is only showing one and not expanding up to 5 items. However the second LABEL Past bookings is working perfectly and showing all items when i scroll up to end.

My java file is:

public class MyBookingActivity extends BaseToolBarActivity implements 
    SwipeRefreshLayout.OnRefreshListener {

    int cancelValue;
    private SwipeRefreshLayout swipeRefreshLayout;
    @BindView(R.id.rv_ongoing_bookings)
    RecyclerView mRVOngoingBookings;
    private List<MyBookingsApi.ApiResponse.Datum> mCourtDataList = new ArrayList<>();
    @BindView(R.id.rv_past_bookings)
    RecyclerView mRVPastBookings;
    private BaseRecyclerAdapter<MyBookingsApi.ApiResponse.Datum, MyBookingsViewHolder> mBaseRecyclerAdapterMyBookings = new BaseRecyclerAdapter<MyBookingsApi.ApiResponse.Datum, MyBookingsViewHolder>(MyBookingsViewHolder.class, R.layout.layout_list_item_my_bookings) {

        @Override
        protected void populateViewHolder(MyBookingsViewHolder itemViewHolder, final MyBookingsApi.ApiResponse.Datum model, int position) {
            String date = null;
            try {
                date = new SimpleDateFormat("yyyy/MM/dd", Locale.ENGLISH).format(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.ENGLISH).parse(model.getDate()));
            } catch (ParseException e) {
                e.printStackTrace();
            }
            String sessions = "N.A.";
            int CancelledValue = model.getCancelled();
            if (CancelledValue == 0)
            {
                itemViewHolder.PaymentYesNo.setText(getString(R.string.booking_detail_no));
                itemViewHolder.PaymentYesNo.setBackgroundResource(R.drawable.round_corner_linear_green);
            }
            else
            {
                itemViewHolder.PaymentYesNo.setText(getString(R.string.booking_detail_yes));
                itemViewHolder.PaymentYesNo.setBackgroundResource(R.drawable.round_corner_linear_red);
            }
            String paymentConfirmed  = model.getPayment_confirmed();
            String paymentType = model.getPaymentType();
            if (paymentConfirmed.equals("true"))
            {
                itemViewHolder.PaymentStatus.setText("Confirmed");

            }
            else
            {
                itemViewHolder.PaymentStatus.setText("Pending");
            }
            if (CancelledValue == 0 && paymentConfirmed.equals("false") && paymentType.equals("cash"))
            {

                itemViewHolder.DepositThisAmount.setText("Deposit " + String.valueOf(model.getDepositAmount()) + " SAR in " +
                String.valueOf(model.getDepositTimeAllowed()) + " HRS");
            }
            else
            {
                itemViewHolder.DepositThisAmount.setVisibility(View.GONE);
            }
            if (model.getSession() != null)
                sessions = model.getSession();
            itemViewHolder.mCustomTextViewCourtBookingTime.setText(date + " " + sessions);
            if (getResources().getConfiguration().locale.equals(new Locale("ar"))) {
                itemViewHolder.mCustomTextViewCourtPrice.setText(model.getPrice() + " " + "ريال");
                itemViewHolder.mCustomTextViewCourtCancellationCutoff.setText("يمكن الغاء الحجز قبل المباراة" + " : " + model.getCancelCutoffTime());
            } else {
                itemViewHolder.mCustomTextViewCourtPrice.setText(getString(R.string.price, model.getPrice()));
                itemViewHolder.mCustomTextViewCourtCancellationCutoff.setText(getString(R.string.cancellation_cutoff, model.getCancelCutoffTime()));
            }
            String cancelshow = model.getCancelshow();
            if (cancelshow.equals("true"))
            {
                cancelValue = 1;
                itemViewHolder.mAppCompatImageViewMoreHoriz.setVisibility(View.VISIBLE);
            }
            else
            {
                cancelValue = 0;
                itemViewHolder.mAppCompatImageViewMoreHoriz.setVisibility(View.GONE);
            }

            itemViewHolder.mCustomTextViewCourtName.setText(model.getCourtName());
            itemViewHolder.mAppCompatImageViewMoreHoriz.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    PopupMenu popup = new PopupMenu(MyBookingActivity.this, v);
                    popup.getMenu().add(0, 1, 0, getString(R.string.my_booking_cancel));


                    //adding click listener
                    popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
                        @Override
                        public boolean onMenuItemClick(MenuItem item) {
                            switch (item.getItemId()) {
                                case 1:
                                    cancelBooking(model.getId());
                                    break;
                                //case 1:
                                  //  deleteBooking(model.getId());
                            }
                            return false;
                        }
                    });
                    //displaying the popup
                    popup.show();
                }
            });
            itemViewHolder.mReaRelativeLayoutMyBooking.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    //launchActivity(MyBookingDetailActivity.getActivityIntent(MyBookingActivity.this, model.getId(), "MyBooking", 1));
                }
            });

            itemViewHolder.mAppCompatImageViewRightArrow.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    launchActivity(MyBookingDetailActivity.getActivityIntent(MyBookingActivity.this, model.getId(), "MyBooking", 1));
                }
            });
        }

    };
    private BaseRecyclerAdapter<PastBookingsApi.ApiResponse.Datum, MyPastBookingsViewHolder> mBaseRecyclerAdapterMyPastBookings = new BaseRecyclerAdapter<PastBookingsApi.ApiResponse.Datum, MyPastBookingsViewHolder>(MyPastBookingsViewHolder.class, R.layout.layout_list_item_my_bookings) {

        @Override
        protected void populateViewHolder(MyPastBookingsViewHolder itemViewHolder, final PastBookingsApi.ApiResponse.Datum model, int position) {
            String date = null;
            try {
                date = new SimpleDateFormat("yyyy/MM/dd", Locale.ENGLISH).format(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.ENGLISH).parse(model.getDate()));
            } catch (ParseException e) {
                e.printStackTrace();
            }
            String sessions = "N.A.";
            int CancelledValue = model.getCancelled();
            if (CancelledValue == 0)
            {
                itemViewHolder.PaymentYesNo.setText(getString(R.string.booking_detail_no));
                itemViewHolder.PaymentYesNo.setBackgroundResource(R.drawable.round_corner_linear_green);
            }
            else
            {
                itemViewHolder.PaymentYesNo.setText(getString(R.string.booking_detail_yes));
                itemViewHolder.PaymentYesNo.setBackgroundResource(R.drawable.round_corner_linear_red);
            }
            itemViewHolder.DepositThisAmount.setVisibility(View.GONE);
            int paymentConfirmed  = model.getPaymentConfirmed();
            if (paymentConfirmed == 1)
            {
                itemViewHolder.PaymentStatus.setText("Confirmed");

            }
            else
            {
                itemViewHolder.PaymentStatus.setText("Pending");
            }
            if (model.getSession() != null)
                sessions = model.getSession();
            itemViewHolder.mCustomTextViewCourtBookingTime.setText(date + " " + sessions);
            if (getResources().getConfiguration().locale.equals(new Locale("ar"))) {
                itemViewHolder.mCustomTextViewCourtPrice.setText(model.getPrice() + " " + "ريال");
            } else {
                itemViewHolder.mCustomTextViewCourtPrice.setText(getString(R.string.price, model.getPrice()));
            }
            itemViewHolder.mCustomTextViewCourtCancellationCutoff.setText(getString(R.string.cancellation_cutoff, "0"));
            itemViewHolder.mCustomTextViewCourtName.setText(model.getCourtName());
            itemViewHolder.mAppCompatImageViewMoreHoriz.setVisibility(View.VISIBLE);
            itemViewHolder.mAppCompatImageViewMoreHoriz.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    PopupMenu popup = new PopupMenu(MyBookingActivity.this, v);
                    popup.getMenu().add(0, 1, 0, getString(R.string.notification_delete));

                    popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
                        @Override
                        public boolean onMenuItemClick(MenuItem item) {
                            switch (item.getItemId()) {
                                case 1:
                                    deleteBooking(model.getId());
                                    break;
                            }
                            return false;
                        }
                    });
                    popup.show();
                }
            });
            itemViewHolder.mAppCompatImageViewRightArrow.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    launchActivity(MyBookingDetailActivity.getActivityIntent(MyBookingActivity.this, model.getId(), "MyBooking", 1));
                }
            });
            itemViewHolder.mReaRelativeLayoutMyBooking.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                   // launchActivity(MyBookingDetailActivity.getActivityIntent(MyBookingActivity.this, model.getId(), "MyBooking", 1));
                }
            });
        }
    };

    public static Intent getActivityIntent(Context context) {
        return new Intent(context, MyBookingActivity.class);
    }

    private void cancelBooking(final int id) {

    }

    private void deleteBooking(final int id) {

    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
        getSupportActionBar().setTitle(getString(R.string.title_activity_my_booking));
        setUpRecyclerView();
        setUpEmptyAdapter();
        swipeRefreshLayout = (SwipeRefreshLayout) findViewById(R.id.swipe_refresh_layout);
        swipeRefreshLayout.setOnRefreshListener(this);
        getMyBooking();
        getMyPastBooking();
        /*swipeRefreshLayout.post(new Runnable() {
                                    @Override
                                    public void run() {
                                        swipeRefreshLayout.setRefreshing(true);

                                        getMyBooking();
                                    }
                                }
        );*/
    }

    private void setUpEmptyAdapter() {
        mRVPastBookings.setAdapter(new BaseEmptyRecyclerAdapter<EmptyViewHolderRefresh>(EmptyViewHolderRefresh.class, R.layout.layout_place_holderrefresh) {
            @Override
            protected void populateEmptyViewHolder(EmptyViewHolderRefresh viewHolder) {
                viewHolder.mAppCompatImageView.setImageResource(R.drawable.no_booking_place_holder);
                viewHolder.mCustomTextViewTitle.setText(R.string.no_bookings_available_title);
                viewHolder.mCustomTextViewDescription.setText(R.string.no_bookings_available_description);
                viewHolder.refreshText.setText(R.string.swipe);
                //viewHolder.mCustomButton.setText(R.string.try_again);
                viewHolder.mCustomButton.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        //getMyPastBooking();
                    }
                });
            }
        });

        mRVOngoingBookings.setAdapter(new BaseEmptyRecyclerAdapter<EmptyViewHolderRefresh>(EmptyViewHolderRefresh.class, R.layout.layout_place_holderrefresh) {
            @Override
            protected void populateEmptyViewHolder(EmptyViewHolderRefresh viewHolder) {
                viewHolder.mAppCompatImageView.setImageResource(R.drawable.no_booking_place_holder);
                viewHolder.mCustomTextViewTitle.setText(R.string.no_bookings_available_title);
                viewHolder.mCustomTextViewDescription.setText(R.string.no_bookings_available_description);
                //viewHolder.mCustomButton.setText(R.string.try_again);
                viewHolder.refreshText.setText(R.string.swipe);
                viewHolder.mCustomButton.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                       // getMyBooking();
                    }
                });
            }
        });
    }

    private void setUpRecyclerView() {
         mRVOngoingBookings.setAdapter(mBaseRecyclerAdapterMyBookings);
        DividerItemDecoration mDividerItemDecorationMyBookings = new DividerItemDecoration(this, LinearLayoutManager.VERTICAL);
        mDividerItemDecorationMyBookings.setDrawable(ContextCompat.getDrawable(this, R.drawable.divider));
        mRVOngoingBookings.addItemDecoration(mDividerItemDecorationMyBookings);

        mRVPastBookings.setAdapter(mBaseRecyclerAdapterMyPastBookings);
        DividerItemDecoration mDividerItemDecorationMyPastBookings = new DividerItemDecoration(this, LinearLayoutManager.VERTICAL);
        mDividerItemDecorationMyPastBookings.setDrawable(ContextCompat.getDrawable(this, R.drawable.divider));
        mRVPastBookings.addItemDecoration(mDividerItemDecorationMyPastBookings);

    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        if (item.getItemId() == android.R.id.home) {
            finishWithResultCancel();
        }
        return super.onOptionsItemSelected(item);
    }

    @Override
    protected int getMenuResource() {
        return RESOURCE_NO_MENU;
    }

    @Override
    protected int getLayoutResource() {
        return R.layout.activity_my_booking;
    }

    @Override
    public void onResume() {
        super.onResume();
        registerEventBus();
        //getMyBooking();
        //getMyPastBooking();
    }

    @Override
    public void onPause() {
        super.onPause();
        unRegisterEventBus();
    }

    private void getMyPastBooking() {
      /// swipeRefreshLayout.setRefreshing(true);
        final ProgressDialog pd = new ProgressDialog(MyBookingActivity.this);
        pd.setMessage("Please wait..");
        pd.show();
        Handler mHandler = new Handler();
        mHandler.postDelayed(new Runnable() {

            @Override
            public void run() {
                pd.dismiss();
                startApiService(PastBookingsApi.getServiceIntent(MyBookingActivity.this, getToken()));
            }

        }, 800);

    }

    private void getMyBooking() {
       // swipeRefreshLayout.setRefreshing(true);
        final ProgressDialog pd = new ProgressDialog(MyBookingActivity.this);
        pd.setMessage("Please wait..");
        pd.show();
        Handler mHandler = new Handler();
        mHandler.postDelayed(new Runnable() {

            @Override
            public void run() {
                pd.dismiss();
                startApiService(MyBookingsApi.getServiceIntent(MyBookingActivity.this, getToken()));
            }

        }, 2000);

        //swipeRefreshLayout.setRefreshing(false);
    }

    @Subscribe(threadMode = ThreadMode.MAIN)
    public void onMessageEvent(BaseApi.EventBusMessage eventBusMessage) {
        switch (eventBusMessage.event) {
            case BaseApi.EventBusMessage.EVENT_SHOW_PROGRESS_DIALOG:
                showProgressDialog();
                break;
            case BaseApi.EventBusMessage.EVENT_HIDE_PROGRESS_DIALOG:
                hideProgressDialog();
                break;
            default:
                if (eventBusMessage.object instanceof MyBookingsApi.ApiResponse)
                    parseMyBookingsSuccessResponse((MyBookingsApi.ApiResponse) eventBusMessage.object);
                else if (eventBusMessage.object instanceof PastBookingsApi.ApiResponse) {
                    parsePastBookingsSuccessResponse((PastBookingsApi.ApiResponse) eventBusMessage.object);
                } else if (eventBusMessage.object instanceof BaseApi.DefaultErrorResponse) {
                    parseErrorResponse((BaseApi.DefaultErrorResponse) eventBusMessage.object);
                } else if (eventBusMessage.object instanceof BaseApi.Error500Response) {
                    //parseError500Response((BaseApi.Error500Response) eventBusMessage.object);
                } else if (eventBusMessage.object instanceof MyBookingCancelApi.ApiResponse) {
                    parseCancelBookingSuccessResponse((MyBookingCancelApi.ApiResponse) eventBusMessage.object);
                } else if (eventBusMessage.object instanceof MyBookingDeleteApi.ApiResponse) {
                    parseDeleteBookingSuccessResponse((MyBookingDeleteApi.ApiResponse) eventBusMessage.object);
                }
                break;
        }
    }

    private void parseDeleteBookingSuccessResponse(MyBookingDeleteApi.ApiResponse apiResponse) {
        showSnackBar(apiResponse.getMessage());
        getMyPastBooking();
    }

    private void parseCancelBookingSuccessResponse(final MyBookingCancelApi.ApiResponse apiResponse) {
        showSnackBar(apiResponse.getMessage());
        getMyBooking();
        /*final ProgressDialog pd = new ProgressDialog(MyBookingActivity.this);
        pd.setMessage("Please wait..");
        pd.show();
        Handler mHandler = new Handler();
        mHandler.postDelayed(new Runnable() {

            @Override
            public void run() {
                pd.dismiss();
                startApiService(MyBookingDeleteApi.getServiceIntent(MyBookingActivity.this, getToken(), apiResponse.getData().getId()));
            }

        }, 800);*/

    }

    private void parsePastBookingsSuccessResponse(PastBookingsApi.ApiResponse apiResponse) {
        List<PastBookingsApi.ApiResponse.Datum> datumList = apiResponse.getData();
        if (datumList.size() > 0) {
            Collections.sort(datumList, new Comparator<PastBookingsApi.ApiResponse.Datum>()
            {
                @Override
                public int compare(PastBookingsApi.ApiResponse.Datum o1, PastBookingsApi.ApiResponse.Datum o2) {
                    return o1.getId() > o2.getId() ? -1 : (o1.getId() < o2.getId() ) ? 1 : 0;
                }
            });
            mRVPastBookings.setAdapter(mBaseRecyclerAdapterMyPastBookings);
            mBaseRecyclerAdapterMyPastBookings.setItems(datumList);
        } else {
            mRVPastBookings.setAdapter(new BaseEmptyRecyclerAdapter<EmptyViewHolderRefresh>(EmptyViewHolderRefresh.class, R.layout.layout_place_holderrefresh) {
                @Override
                protected void populateEmptyViewHolder(EmptyViewHolderRefresh viewHolder) {
                    viewHolder.mAppCompatImageView.setImageResource(R.drawable.no_booking_place_holder);
                    viewHolder.mCustomTextViewTitle.setText(R.string.no_bookings_available_title);
                    viewHolder.mCustomTextViewDescription.setText(R.string.no_bookings_available_description);
                   // viewHolder.mCustomButton.setText(R.string.try_again);
                    viewHolder.refreshText.setText(R.string.swipe);
                    viewHolder.mCustomButton.setOnClickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View v) {
                           // getMyPastBooking();
                        }
                    });
                }
            });
        }
    }

    private void parseMyBookingsSuccessResponse(MyBookingsApi.ApiResponse apiResponse) {
       // mCourtDataList = apiResponse.getData();
        List<MyBookingsApi.ApiResponse.Datum> datumList = apiResponse.getData();
        if (datumList.size() > 0) {
            Collections.sort(datumList, new Comparator<MyBookingsApi.ApiResponse.Datum>()
            {
                @Override
                public int compare(MyBookingsApi.ApiResponse.Datum o1, MyBookingsApi.ApiResponse.Datum o2) {
                    return o1.getId() > o2.getId() ? -1 : (o1.getId() < o2.getId() ) ? 1 : 0;
                }
            });

            mRVOngoingBookings.setAdapter(mBaseRecyclerAdapterMyBookings);
            mBaseRecyclerAdapterMyBookings.setItems(datumList);
        } else {
            mRVOngoingBookings.setAdapter(new BaseEmptyRecyclerAdapter<EmptyViewHolderRefresh>(EmptyViewHolderRefresh.class, R.layout.layout_place_holderrefresh) {
                @Override
                protected void populateEmptyViewHolder(EmptyViewHolderRefresh viewHolder) {
                    viewHolder.mAppCompatImageView.setImageResource(R.drawable.no_booking_place_holder);
                    viewHolder.mCustomTextViewTitle.setText(R.string.no_bookings_available_title);
                    viewHolder.mCustomTextViewDescription.setText(R.string.no_bookings_available_description);
                    //viewHolder.mCustomButton.setText(R.string.try_again);
                    viewHolder.refreshText.setText(R.string.swipe);
                    viewHolder.mCustomButton.setOnClickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View v) {
                            //getMyBooking();
                        }
                    });
                }
            });
        }
    }

    private void parseError500Response(BaseApi.Error500Response error500Response) {
        showAlertDialog(R.string.session_timeout_title, R.string.session_timeout_message, new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                logout();
            }
        });
    }

    private void parseErrorResponse(BaseApi.DefaultErrorResponse defaultErrorResponse) {
        showSnackBar(defaultErrorResponse.getMessage());
    }

    @Subscribe(threadMode = ThreadMode.MAIN)
    public void noInternet(String message) {
        mRVOngoingBookings.setAdapter(new BaseEmptyRecyclerAdapter<EmptyViewHolderRefresh>(EmptyViewHolderRefresh.class, R.layout.layout_place_holderrefresh) {
            @Override
            protected void populateEmptyViewHolder(EmptyViewHolderRefresh viewHolder) {
                viewHolder.mAppCompatImageView.setImageResource(R.drawable.no_internet_placeholder);
                viewHolder.mCustomTextViewTitle.setText(R.string.connection_problem_title);
                viewHolder.mCustomTextViewDescription.setText(R.string.connection_problem_description);
                viewHolder.refreshText.setText(R.string.swipe);
                //viewHolder.mCustomButton.setText(R.string.try_again);
                viewHolder.mCustomButton.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                       // getMyBooking();
                    }
                });
            }
        });
        mRVPastBookings.setAdapter(new BaseEmptyRecyclerAdapter<EmptyViewHolderRefresh>(EmptyViewHolderRefresh.class, R.layout.layout_place_holderrefresh) {
            @Override
            protected void populateEmptyViewHolder(EmptyViewHolderRefresh viewHolder) {
                viewHolder.mAppCompatImageView.setImageResource(R.drawable.no_internet_placeholder);
                viewHolder.mCustomTextViewTitle.setText(R.string.connection_problem_title);
                viewHolder.mCustomTextViewDescription.setText(R.string.connection_problem_description);
                viewHolder.refreshText.setText(R.string.swipe);
                //viewHolder.mCustomButton.setText(R.string.try_again);
                viewHolder.mCustomButton.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                       // getMyPastBooking();
                    }
                });
            }
        });
    }
}

and activity_my_booking layout is:

 <?xml version="1.0" encoding="utf-8"?>

<android.support.v4.widget.SwipeRefreshLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/swipe_refresh_layout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <android.support.design.widget.CoordinatorLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:id="@+id/coordinatorLayout"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <include layout="@layout/layout_toolbar" />

        <include layout="@layout/content_my_booking" />
    </android.support.design.widget.CoordinatorLayout>
</android.support.v4.widget.SwipeRefreshLayout>

Set the first RecyclerView’s height to wrap_content and set setNestedScrollingEnabled to false

RecyclerView rv_ongoing_bookings= (RecyclerView) findViewById(R.id.rv_ongoing_bookings);
rv_ongoing_bookings.setNestedScrollingEnabled(false);

You shouldn't use RecyclerView inside a NestedScrollView because RecyclerView don't recycle anything in a NestedScrollView(You can test it with write log in onCreateView and onBindView). Change the container layout type like LinearLayout, RelativeLayout etc. I would recommend you to go with pagination. RecyclerView also supports nested scrolling by implementing the NestedScrollingChild3 interface, which means it can cooperate with a parent view implementing NestedScrollingParent3 when both are

To achieve it my approach would be to customize my recyclerView adapter to act as a section header recycler view, something like this: https://android-arsenal.com/details/1/4495

Now what kinda problem occurred when we used nestedScrollView and put recyclerView inside nestedScrollView , it scrolls at various speeds  As we already know that recyclerView has a smooth scrolling by itself but when we need to put recyclerView within any scrollView it will not work like the below code snippet: The solution for this is…

The following code will make recycler view expandable...

public class ExpandableRecyclerView extends RecyclerView
{
private boolean expanded = false;

public ExpandableRecyclerView(Context context, AttributeSet attrs, int defStyle)
{
    super(context, attrs, defStyle);
}

public ExpandableRecyclerView(Context context)
{
    super(context);
}

public ExpandableRecyclerView(Context context, AttributeSet attrs)
{
    super(context, attrs);
}

public boolean isExpanded()
{
    return expanded;
}

@Override
public void onMeasure(int widthMeasureSpec, int heightMeasureSpec)
{
    if (isExpanded())
    {
        int expandSpec = MeasureSpec.makeMeasureSpec(MEASURED_SIZE_MASK, MeasureSpec.AT_MOST);
        super.onMeasure(widthMeasureSpec, expandSpec);

        ViewGroup.LayoutParams params = getLayoutParams();
        params.height = getMeasuredHeight();
    }
    else
    {
        super.onMeasure(widthMeasureSpec, heightMeasureSpec);
    }
}

public void setExpanded(boolean expanded)
{
    this.expanded = expanded;
}
}

Usage... use it the way you use recycler view... just set recyclerView.setExpanded(true);

You may directly use it inside scrollview...

Coordinator (Nested Scroll ( Image View and Recycler View)). “Load More RecyclerView inside Nested Scroll View and Coordinator Layout” is  You can’t use a recycler view within a nested scroll view. It’s not intended to contain further scrollable views but it’s because it’s a child of a scrolling layout itself that you need the nested scrolling view.

So, it's not really an answer to your question, it's more like a suggestion to use RecyclerView as it should be depending on the screenshot which you included in your question. You really don't need to create two RecyclerView's to achieve the layout which you need. As I understand you want to show some items and put a separator with text depending on something (Booking's date as I can see).

In RecyclerView.Adapter you have getItemViewType where you can return an int value depending on some variables.For example your getItemViewType should look something like this:

@Override
public int getItemViewType(int position) {
    MyObject myObject = mItems.get(position);
    // myObject.isSeparator() is a sample function which helps you identify it you should show construct a booking view or separator
    if(myObject.isSeparator()){
        // this variable is declared inside your Adapter ->
        // private static final int VIEW_TYPE_SEPARATOR = 1;
        return VIEW_TYPE_SEPARATOR;
    }
    // private static final int VIEW_TYPE_BOOKING = 0;
    return VIEW_TYPE_BOOKING;
}

Depending on those values you need to create two ViewHolder's :

@Override
public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
    if (VIEW_TYPE_SEPARATOR == viewType) {
       new SeparatorViewHolder(/* Some params which you need here */);
    }
    return new BookingViewHolder(/* Some other params which you need here */);
}

And ->

@Override
public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) {
    if (VIEW_TYPE_SEPARATOR == getItemViewType(position)) {
        // Populate SeparatorViewHolder
    } else {
        // Populate BookingViewHolder
    }
}

And at the end you should populate your List with the objects you need to determine if the item is a Booking item for example or a Separator.

I hope you got the main idea.

This example demonstrates how do I use RecyclerView inside NestedScrollView in android.Step 1 − Create a new project in Android Studio,  The solution we came up with is to temporarily skip RecyclerView‘s implementation of onInterceptTouchEvent as long as a NestedScrollChild is scrolling and is actually able to scroll in the

The problem that usually arise is that both RecyclerView and NestedScrollView support ScrollView. When you have one inside the other, the scrolling of the  Android – RecyclerView inside NestedScrollView Example In android, there are times when you will have the need to add RecyclerView inside a NestedScrollView. The problem that usually arise is that both RecyclerView and NestedScrollView support ScrollView.

[x ] I have searched existing issues and confirmed this is not a duplicate Issues and steps to reproduce RecyclerView is not showing all items  Recycler View is one of the most used view components in android. Also, the design of recycler views is getting complex day by day such as Recycler View with multiple view types, nested recycler view, nested recycler view with multiple view types.

I am using RecyclerView inside NestedScrollView and it works. But when I use RecyclerView inside LinearLayout or something, it scroll in  When the user swipes the side-wise the inner RecyclerView recycles the views and gives you a smooth scroll. But this is not the case when the user scrolls vertically. Each of the views of the inner RecyclerView is inflated again. This is because each of the the nested RecyclerViews has a view pool of its own.

Comments
  • Your implementation is so wrong! You should not use two RecyclerViews in this case. You can achieve the same effect using different view types inside your RecyclerView's Adapter and it will work in a much better way.
  • @hardartcore Can you explain a little bit please
  • Just a note, never use recyclerview(s) inside NestedScrollView, you will have UI performance issues.
  • whether issue solved?
  • no its not working. The recycler view still showing only the ffirst item and not expanded up to its full height. What is the purpose of using this line "app:layoutManager="android.support.v7.widget.LinearLayoutManager". Is thats the cause of issue?
  • It is used to set the layout manager for recyclerview, if you are also setting layout manager in java than no need to mention here.
  • if you want you can remove that line and recyclerView.setLayoutManager(new LinearLayoutManager(this));
  • Iam using these three lines in java code DividerItemDecoration mDividerItemDecorationMyBookings = new DividerItemDecoration(this, LinearLayoutManager.VERTICAL); mDividerItemDecorationMyBookings.setDrawable(ContextCompat.getDrawable(this, R.drawable.divider)); mRVOngoingBookings.addItemDecoration(mDividerItemDecorationMyBookings);
  • That is for adding divider line between items
  • I have to put this code in new class and then use it like mRvOngoingBookings.setExpanded(true); ?
  • if possible replace and use this class for both recycler view..and then set the setExpandable to true for both recycler view...its same as recycler view only..it might help you....
  • Ok let me try with this