Skip to content

Commit

Permalink
fix ViewHolder views must not be attached when created
Browse files Browse the repository at this point in the history
  • Loading branch information
youlookwhat committed May 10, 2022
1 parent 9f56ddd commit 602e94e
Showing 1 changed file with 25 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 602e94e

Please sign in to comment.