RecyclerView does not display data

I have a RecyclerView, which is a BottomSheet, from the 23.2 support library:

<android.support.v7.widget.RecyclerView
        android:id="@+id/bottom_sheet_multi_car"
        android:layout_width="match_parent"
        android:layout_height="@dimen/bottom_sheet_height"
        android:background="@color/background"
        app:layout_behavior="android.support.design.widget.BottomSheetBehavior"/>

First, I create an adapter with an empty dataset:

    mMultiCarAdapter = new CarListRecyclerAdapter();
    bottomSheetMultiCar.addItemDecoration(new DividerItemDecoration(getActivity(), DividerItemDecoration.VERTICAL_LIST));
    bottomSheetMultiCar.setLayoutManager(new LinearLayoutManager(getContext()));
    bottomSheetMultiCar.setAdapter(mMultiCarAdapter);
    ...

public static class CarListRecyclerAdapter extends RecyclerView.Adapter<CarListRecyclerAdapter.ViewHolder> {
    private List<Car> mCars = new ArrayList<>();

I have a method to replace my data:

    public void replaceItems(final List<Car> cars) {
        mCars.clear();
        mCars.addAll(cars);
        notifyDataSetChanged();
    }

Showing RecyclerView:

private void showMultiCar(final List<Car> cars) {
    mBottomSheetMultiCarBehavior.setState(BottomSheetBehavior.STATE_COLLAPSED);

    mMultiCarAdapter.replaceItems(cars);
}

After I show the RecyclerView, it appears (I see the BottomSheet with the background color of the RecyclerView). However, no elements are visible ... until I do some action. Confirmed actions that display RecyclerView items:

  • I change the visibility of other representations;
  • I click RecyclerView

I have tried several things.

Firstly, changing the visibility of the RecyclerView after adding items, but it seems like some time needs to be taken for this.

I tried several methods on it: requestLayout, invalidate.

+4
1

:

mRecyclerView.setHasFixedSize(true);

, . , , .

+1

All Articles