1

I have this code

public class CustomLinearLayoutManager extends LinearLayoutManager
{
    @Override
    public void onLayoutChildren(RecyclerView.Recycler recycler, RecyclerView.State state)
    {
        super.onLayoutChildren(recycler, state);

        int childCount = getChildCount();
        View lastChild = getChildAt(childCount - 1);

        // Do some stuff
    }
}

For some reason sometimes lastChild is null. How can it be?

As mentioned in comments, lastChild is null because there is no childs at all, so new question is why there is no childs after calling super.onLayoutChildren(recycler, state);?

s.maks
  • 2,583
  • 1
  • 23
  • 27

1 Answers1

0

It seems that for some reason, there are no views that have this layout has a parent. Can you post your xml?

Ruben2112
  • 423
  • 4
  • 18