Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LoadMoreWrapper #118

Open
a120476536 opened this issue Dec 19, 2017 · 1 comment
Open

LoadMoreWrapper #118

a120476536 opened this issue Dec 19, 2017 · 1 comment

Comments

@a120476536
Copy link

Error:(16, 8) 错误: 类LoadMoreWrapper是公共的, 应在名为 LoadMoreWrapper.java 的文件中声明
这个类报错 大神
`package com.zhy.adapter.recyclerview.wrapper;

import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.StaggeredGridLayoutManager;
import android.view.View;
import android.view.ViewGroup;

import com.zhy.adapter.recyclerview.base.ViewHolder;
import com.zhy.adapter.recyclerview.utils.WrapperUtils;

/**

  • Created by zhy on 16/6/23.
    */
    public class LoadMoreWrapper extends RecyclerView.Adapter<RecyclerView.ViewHolder>
    {
    public static final int ITEM_TYPE_LOAD_MORE = Integer.MAX_VALUE - 2;

    private RecyclerView.Adapter mInnerAdapter;
    private View mLoadMoreView;
    private int mLoadMoreLayoutId;

    public LoadMoreWrapper(RecyclerView.Adapter adapter)
    {
    mInnerAdapter = adapter;
    }

    private boolean hasLoadMore()
    {
    return mLoadMoreView != null || mLoadMoreLayoutId != 0;
    }

    private boolean isShowLoadMore(int position)
    {
    return hasLoadMore() && (position >= mInnerAdapter.getItemCount());
    }

    @OverRide
    public int getItemViewType(int position)
    {
    if (isShowLoadMore(position))
    {
    return ITEM_TYPE_LOAD_MORE;
    }
    return mInnerAdapter.getItemViewType(position);
    }

    @OverRide
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType)
    {
    if (viewType == ITEM_TYPE_LOAD_MORE)
    {
    ViewHolder holder;
    if (mLoadMoreView != null)
    {
    holder = ViewHolder.createViewHolder(parent.getContext(), mLoadMoreView);
    } else
    {
    holder = ViewHolder.createViewHolder(parent.getContext(), parent, mLoadMoreLayoutId);
    }
    return holder;
    }
    return mInnerAdapter.onCreateViewHolder(parent, viewType);
    }

    @OverRide
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position)
    {
    if (isShowLoadMore(position))
    {
    if (mOnLoadMoreListener != null)
    {
    mOnLoadMoreListener.onLoadMoreRequested();
    }
    return;
    }
    mInnerAdapter.onBindViewHolder(holder, position);
    }

    @OverRide
    public void onAttachedToRecyclerView(RecyclerView recyclerView)
    {
    WrapperUtils.onAttachedToRecyclerView(mInnerAdapter, recyclerView, new WrapperUtils.SpanSizeCallback()
    {
    @OverRide
    public int getSpanSize(GridLayoutManager layoutManager, GridLayoutManager.SpanSizeLookup oldLookup, int position)
    {
    if (isShowLoadMore(position))
    {
    return layoutManager.getSpanCount();
    }
    if (oldLookup != null)
    {
    return oldLookup.getSpanSize(position);
    }
    return 1;
    }
    });
    }

    @OverRide
    public void onViewAttachedToWindow(RecyclerView.ViewHolder holder)
    {
    mInnerAdapter.onViewAttachedToWindow(holder);

     if (isShowLoadMore(holder.getLayoutPosition()))
     {
         setFullSpan(holder);
     }
    

    }

    private void setFullSpan(RecyclerView.ViewHolder holder)
    {
    ViewGroup.LayoutParams lp = holder.itemView.getLayoutParams();

     if (lp != null
             && lp instanceof StaggeredGridLayoutManager.LayoutParams)
     {
         StaggeredGridLayoutManager.LayoutParams p = (StaggeredGridLayoutManager.LayoutParams) lp;
    
         p.setFullSpan(true);
     }
    

    }

    @OverRide
    public int getItemCount()
    {
    return mInnerAdapter.getItemCount() + (hasLoadMore() ? 1 : 0);
    }

    public interface OnLoadMoreListener
    {
    void onLoadMoreRequested();
    }

    private OnLoadMoreListener mOnLoadMoreListener;

    public LoadMoreWrapper setOnLoadMoreListener(OnLoadMoreListener loadMoreListener)
    {
    if (loadMoreListener != null)
    {
    mOnLoadMoreListener = loadMoreListener;
    }
    return this;
    }

    public LoadMoreWrapper setLoadMoreView(View loadMoreView)
    {
    mLoadMoreView = loadMoreView;
    return this;
    }

    public LoadMoreWrapper setLoadMoreView(int layoutId)
    {
    mLoadMoreLayoutId = layoutId;
    return this;
    }
    }
    `

@BloomSong
Copy link

修改文件的文件名为LoadMoreWrapper,原始为LoadmoreWrapper(m是小写的)。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants