/** * remove all footer view from mFooterLayout and set null to mFooterLayout */ public void removeAllFooterView() { if (getFooterLayoutCount() == 0) return; mFooterLayout.removeAllViews(); int position = getFooterViewPosition(); if (position != -1) { notifyItemRemoved(position); } }
/** * Add footer view to mFooterLayout and set footer view position in mFooterLayout. * When index = -1 or index >= child count in mFooterLayout, * the effect of this method is the same as that of {@link #addFooterView(View)}. * * @param footer * @param index the position in mFooterLayout of this footer. * When index = -1 or index >= child count in mFooterLayout, * the effect of this method is the same as that of {@link #addFooterView(View)}. */ public void addFooterView(View footer, int index, int orientation) { if (mFooterLayout == null) { mFooterLayout = new LinearLayout(footer.getContext()); if (orientation == LinearLayout.VERTICAL) { mFooterLayout.setOrientation(LinearLayout.VERTICAL); mFooterLayout.setLayoutParams(new LayoutParams(MATCH_PARENT, WRAP_CONTENT)); } else { mFooterLayout.setOrientation(LinearLayout.HORIZONTAL); mFooterLayout.setLayoutParams(new LayoutParams(WRAP_CONTENT, MATCH_PARENT)); } } index = index >= mFooterLayout.getChildCount() ? -1 : index; mFooterLayout.addView(footer, index); if (mFooterLayout.getChildCount() == 1) { int position = getFooterViewPosition(); if (position != -1) { notifyItemInserted(position); } } }
/** * remove footer view from mFooterLayout, * When the child count of mFooterLayout is 0, mFooterLayout will be set to null. * * @param footer */ public void removeFooterView(View footer) { if (getFooterLayoutCount() == 0) return; mFooterLayout.removeView(footer); if (mFooterLayout.getChildCount() == 0) { int position = getFooterViewPosition(); if (position != -1) { notifyItemRemoved(position); } } }