Skip to content

Load more recycler view#71

Open
JackyBower wants to merge 4 commits into
masterfrom
load-more-recycler-view
Open

Load more recycler view#71
JackyBower wants to merge 4 commits into
masterfrom
load-more-recycler-view

Conversation

@JackyBower
Copy link
Copy Markdown

  • load more主要代码

private void initData() {
//初始化LinearLayoutManager
LinearLayoutManager layoutManager = new LinearLayoutManager(getApplicationContext());
layoutManager.setOrientation(LinearLayoutManager.VERTICAL);
mRecyclerView.setLayoutManager(layoutManager);

//默认动画
mRecyclerView.setItemAnimator(new DefaultItemAnimator());
// 在代码中实现列表动画效果
Animation animation = (Animation) AnimationUtils.loadAnimation(getApplicationContext(), R.anim.list_anim);
LayoutAnimationController lac = new LayoutAnimationController(animation);
lac.setDelay(0.2f);  //设置动画间隔时间
lac.setOrder(LayoutAnimationController.ORDER_NORMAL); //设置列表的显示顺序
mRecyclerView.setLayoutAnimation(lac);  //为ListView 添加动画

//初始化RecyclerViewAdapter,并设置ItemViewType
cubeRecyclerViewAdapter = new CubeRecyclerViewAdapter<Laws>() {
    @Override
    protected int getDataItemViewType(int position) {
        return dataItemViewType;
    }
};
// 把Adapter填充到loadMoreRecycleViewContainer中
loadMoreRecycleViewContainer.setCubeRecyclerViewAdapter(cubeRecyclerViewAdapter);
//自定义的ViewHolder,持有每个Item的的所有界面元素
cubeRecyclerViewAdapter.setViewHolderClass(dataItemViewType, this, ViewHolder.class);
//数据集合,可自行替换
if (result.getRows() != null && result.getRows().size() > 0) {
    mListData.addAll(result.getRows());
    //判断是否要加载更多,false为手动执行
    loadMoreRecycleViewContainer.setAutoLoadMore(false);
    loadMoreRecycleViewContainer.useDefaultFooter();
    loadMoreRecycleViewContainer.loadMoreFinish(this.mListData.isEmpty(), this.mListData.size() < result.getTotal());
}
//把数据集合填充cubeRecyclerViewAdapter中
cubeRecyclerViewAdapter.setList(mListData);
//把cubeRecyclerViewAdapter填充到mRecyclerView,并展示
mRecyclerView.setAdapter(cubeRecyclerViewAdapter);

}

private class ViewHolder extends ViewHolderBase {

private TextView textViewName, textViewTop, textViewButtom;

@Override
public View createView(LayoutInflater layoutInflater) {
    View view = layoutInflater.inflate(R.layout.common_list_item, null);
    textViewName = (TextView) view.findViewById(R.id.tv_titleName);
    return view;
}

@Override
public void showData(int position, Laws itemData) {
    textViewName.setText(itemData.getLawName());
}

}

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

Successfully merging this pull request may close these issues.

2 participants