@@ -65,6 +65,7 @@ public class OmegaRecyclerView extends ExpandedRecyclerView implements SwipeMenu
6565 private DividerItemDecoration mDividerItemDecoration ;
6666 private int mItemSpace ;
6767 private int mDividerSize ;
68+ private boolean mIsAdapterConnected ;
6869
6970 public OmegaRecyclerView (Context context ) {
7071 super (context );
@@ -175,6 +176,7 @@ private void initStickyMode(TypedArray a) {
175176 @ Override
176177 @ SuppressWarnings ("unchecked" )
177178 public void setAdapter (RecyclerView .Adapter adapter ) {
179+ mIsAdapterConnected = true ;
178180 unregisterObservers ();
179181
180182 if (adapter == null ) {
@@ -303,6 +305,38 @@ public void addView(View view, int index, ViewGroup.LayoutParams params) {
303305 }
304306 }
305307
308+ @ Override
309+ public int getChildCount () {
310+ if (!mIsAdapterConnected && areSectionsInitialized ()) {
311+ return super .getChildCount () + mHeadersList .size () + mFooterList .size ();
312+ }
313+
314+ return super .getChildCount ();
315+ }
316+
317+ @ Override
318+ public View getChildAt (int index ) {
319+ if (!mIsAdapterConnected && areSectionsInitialized ()) {
320+ int realChildrenCount = super .getChildCount ();
321+ int headersCount = mHeadersList .size ();
322+ int footersCount = mFooterList .size ();
323+
324+ if (index < realChildrenCount ) {
325+ return super .getChildAt (index );
326+ } else if (index < realChildrenCount + headersCount ) {
327+ return mHeadersList .get (index - realChildrenCount );
328+ } else if (index < realChildrenCount + headersCount + footersCount ) {
329+ return mFooterList .get (index - realChildrenCount - headersCount );
330+ }
331+
332+ }
333+ return super .getChildAt (index );
334+ }
335+
336+ private boolean areSectionsInitialized () {
337+ return mHeadersList != null && mFooterList != null ;
338+ }
339+
306340 @ Override
307341 protected void onFinishInflate () {
308342 super .onFinishInflate ();
0 commit comments