Search in sources :

Example 1 with LoadMoreRecyclerViewAdapter

use of me.dkzwm.widget.srl.sample.adapter.LoadMoreRecyclerViewAdapter in project SmoothRefreshLayout by dkzwm.

the class TestBaseRecyclerViewAdapterActivity method onCreate.

@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    getSupportActionBar().setDisplayShowHomeEnabled(true);
    getSupportActionBar().setTitle(R.string.test_base_recyclerView_adapter);
    setContentView(R.layout.activity_test_base_recyclerview_adapter);
    mRefreshLayout = findViewById(R.id.smoothRefreshLayout_test_base_recyclerView_adapter);
    ClassicHeader classicHeader = new ClassicHeader(this);
    classicHeader.setLastUpdateTimeKey("header_last_update_time");
    mRefreshLayout.setHeaderView(classicHeader);
    mRefreshLayout.setOnRefreshListener(new RefreshingListenerAdapter() {

        @Override
        public void onRefreshing() {
            mHandler.postDelayed(new Runnable() {

                @Override
                public void run() {
                    List<String> list = DataUtil.createList(mCount, 20);
                    mCount = list.size();
                    mAdapter.setNewData(list);
                    mRefreshLayout.refreshComplete();
                }
            }, 2000);
        }
    });
    mAdapter = new LoadMoreRecyclerViewAdapter(this);
    mAdapter.setOnLoadMoreListener(new BaseQuickAdapter.RequestLoadMoreListener() {

        @Override
        public void onLoadMoreRequested() {
            mHandler.postDelayed(new Runnable() {

                @Override
                public void run() {
                    List<String> list = DataUtil.createList(mCount, 20);
                    mCount += list.size();
                    mAdapter.addData(list);
                    mAdapter.loadMoreComplete();
                    mRefreshLayout.refreshComplete();
                }
            }, 2000);
        }
    }, mRecyclerView);
    mRefreshLayout.autoRefresh(true);
    mRecyclerView = findViewById(R.id.recyclerView_test_base_recyclerView_adapter);
    mRecyclerView.setOverScrollMode(View.OVER_SCROLL_NEVER);
    mRecyclerView.setLayoutManager(new LinearLayoutManager(this));
    mRecyclerView.setHasFixedSize(true);
    mRecyclerView.setAdapter(mAdapter);
}
Also used : ClassicHeader(me.dkzwm.widget.srl.extra.header.ClassicHeader) RefreshingListenerAdapter(me.dkzwm.widget.srl.RefreshingListenerAdapter) LoadMoreRecyclerViewAdapter(me.dkzwm.widget.srl.sample.adapter.LoadMoreRecyclerViewAdapter) BaseQuickAdapter(com.chad.library.adapter.base.BaseQuickAdapter) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager)

Aggregations

LinearLayoutManager (androidx.recyclerview.widget.LinearLayoutManager)1 BaseQuickAdapter (com.chad.library.adapter.base.BaseQuickAdapter)1 RefreshingListenerAdapter (me.dkzwm.widget.srl.RefreshingListenerAdapter)1 ClassicHeader (me.dkzwm.widget.srl.extra.header.ClassicHeader)1 LoadMoreRecyclerViewAdapter (me.dkzwm.widget.srl.sample.adapter.LoadMoreRecyclerViewAdapter)1