getChildCount() and getChildAt() return zero for RecyclerView
I assume you are calling those methods before layout is calculated.
When you set the adapter, the layout will happen in the next view tree traversal. You can consider adding a ViewTreeObserver.
The function is called when the view is not ready that's why it returns zero, use post() method will help.
myRView.post(new Runnable() {
@Override
public void run() {
Log.show("myRView.post " + myRView.getChildCount());
View childView = myRView.getChildAt(0);
}
});
getChildCount()
may return 0 if you forget to set LayoutManager to RecyclerView.
myRView.setLayoutManager(mLayoutManager);
You could use your adapter getItemCount() function.
myRView.getAdapter.getItemCount();