diff --git a/ByRecyclerview/src/main/java/me/jingbin/library/ByRecyclerView.java b/ByRecyclerview/src/main/java/me/jingbin/library/ByRecyclerView.java index cfa4957..b1b2ad3 100644 --- a/ByRecyclerview/src/main/java/me/jingbin/library/ByRecyclerView.java +++ b/ByRecyclerview/src/main/java/me/jingbin/library/ByRecyclerView.java @@ -536,14 +536,36 @@ Adapter getOriginalAdapter() { public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { if (viewType == TYPE_REFRESH_HEADER) { return new SimpleViewHolder((View) mRefreshHeader); + } else if (viewType == TYPE_LOAD_MORE_VIEW) { + return new SimpleViewHolder((View) mLoadMore); } else if (isHeaderType(viewType)) { - return new SimpleViewHolder(getHeaderViewByType(viewType)); + // headerView + View headerView = getHeaderViewByType(viewType); + if (headerView != null && headerView.getParent() != null && headerView.getParent() instanceof ViewGroup) { + ViewGroup ViewParent = (ViewGroup) headerView.getParent(); + if (ViewParent != null) { + ViewParent.removeView(headerView); + } + } + return new SimpleViewHolder(headerView); } else if (viewType == TYPE_STATE_VIEW) { + // stateView + if (mStateLayout != null && mStateLayout.getParent() != null && mStateLayout.getParent() instanceof ViewGroup) { + ViewGroup ViewParent = (ViewGroup) mStateLayout.getParent(); + if (ViewParent != null) { + ViewParent.removeView(mStateLayout); + } + } return new SimpleViewHolder(mStateLayout); } else if (viewType == TYPE_FOOTER_VIEW) { + // footerView + if (mFooterLayout != null && mFooterLayout.getParent() != null && mFooterLayout.getParent() instanceof ViewGroup) { + ViewGroup ViewParent = (ViewGroup) mFooterLayout.getParent(); + if (ViewParent != null) { + ViewParent.removeView(mFooterLayout); + } + } return new SimpleViewHolder(mFooterLayout); - } else if (viewType == TYPE_LOAD_MORE_VIEW) { - return new SimpleViewHolder((View) mLoadMore); } ViewHolder viewHolder = adapter.onCreateViewHolder(parent, viewType); bindViewClickListener(viewHolder);