android_为recyclerView添加headerView和footerView以及recyclerview的刷新

GitHub https://github.com/hongyangAndroid/baseAdapter

CSDN https://blog.csdn.net/lmj623565791/article/details/51118836

紧接着上一篇

添加head和foot

headerAndFooterWrapper = new HeaderAndFooterWrapper(adapter);
TextView t1 = new TextView(this); t1.setText("Header 1");
TextView t2 = new TextView(this); t2.setText("Header 2");
headerAndFooterWrapper.addHeaderView(t1);
headerAndFooterWrapper.addFootView(t2);
recyclerView.setAdapter(headerAndFooterWrapper);
headerAndFooterWrapper.notifyDataSetChanged();re

loadmore加载更多

mLoadMoreWrapper = new LoadMoreWrapper(adapter);
mLoadMoreWrapper.setLoadMoreView(R.layout.item_img);
mLoadMoreWrapper.setOnLoadMoreListener(new LoadMoreWrapper.OnLoadMoreListener() {
    @Override public void onLoadMoreRequested() {
                Toast.makeText(ThirdActivity.this,"aaaaaaaaaaaaaaaaaaaa",Toast.LENGTH_SHORT).show();
    } });
recyclerView.setAdapter(mLoadMoreWrapper);

recyclerview滚动到底部刷新

recyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
    @Override
    public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
        super.onScrollStateChanged(recyclerView, newState);
        if (newState == RecyclerView.SCROLL_STATE_IDLE) {
            Toast.makeText(ThirdActivity.this, "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", Toast.LENGTH_SHORT).show();
        }
    }

    @Override
    public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
        super.onScrolled(recyclerView, dx, dy);
    }
});

这种方法也能实现分页效果 但是感觉没有smart好用

你可能感兴趣的:(android_为recyclerView添加headerView和footerView以及recyclerview的刷新)