Search in sources :

Example 1 with HorizontalRecyclerViewAdapter

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

the class TestHorizontalRecyclerViewActivity method onCreate.

@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_with_horizontal_recyclerview);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    getSupportActionBar().setDisplayShowHomeEnabled(true);
    getSupportActionBar().setTitle(R.string.test_horizontal_recyclerView);
    mRecyclerView = findViewById(R.id.recyclerView_with_horizontal_recyclerView);
    mRecyclerView.setLayoutManager(new GridLayoutManager(this, 3, LinearLayoutManager.HORIZONTAL, false));
    mRecyclerView.setHasFixedSize(true);
    mAdapter = new HorizontalRecyclerViewAdapter(this, getLayoutInflater());
    mRecyclerView.setAdapter(mAdapter);
    mRefreshLayout = findViewById(R.id.smoothRefreshLayout_with_horizontal_recyclerView);
    MaterialHeader header = new MaterialHeader(this);
    header.setColorSchemeColors(new int[] { Color.RED, Color.BLUE, Color.GREEN, Color.BLACK });
    header.setPadding(PixelUtl.dp2px(this, 25), 0, PixelUtl.dp2px(this, 25), 0);
    mRefreshLayout.setHeaderView(header);
    MaterialFooter footer = new MaterialFooter(this);
    footer.setProgressBarColors(new int[] { Color.RED, Color.BLUE, Color.GREEN, Color.BLACK });
    mRefreshLayout.setFooterView(footer);
    mRefreshLayout.setDisableLoadMore(false);
    mRefreshLayout.setEnableAutoLoadMore(true);
    mRefreshLayout.setEnablePinContentView(true);
    mRefreshLayout.setEnablePinRefreshViewWhileLoading(true);
    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.updateData(list);
                    mRefreshLayout.refreshComplete();
                }
            }, 3000);
        }

        @Override
        public void onLoadingMore() {
            Toast.makeText(TestHorizontalRecyclerViewActivity.this, R.string.has_been_triggered_to_load_more, Toast.LENGTH_SHORT).show();
            mHandler.postDelayed(new Runnable() {

                @Override
                public void run() {
                    List<String> list = DataUtil.createList(mCount, 20);
                    mCount += list.size();
                    mAdapter.appendData(list);
                    mRefreshLayout.refreshComplete();
                }
            }, 3000);
        }
    });
    mRefreshLayout.setDurationToClose(800);
    mRefreshLayout.autoRefresh(false);
}
Also used : MaterialHeader(me.dkzwm.widget.srl.extra.header.MaterialHeader) MaterialFooter(me.dkzwm.widget.srl.extra.footer.MaterialFooter) RefreshingListenerAdapter(me.dkzwm.widget.srl.RefreshingListenerAdapter) GridLayoutManager(androidx.recyclerview.widget.GridLayoutManager) HorizontalRecyclerViewAdapter(me.dkzwm.widget.srl.sample.adapter.HorizontalRecyclerViewAdapter)

Aggregations

GridLayoutManager (androidx.recyclerview.widget.GridLayoutManager)1 RefreshingListenerAdapter (me.dkzwm.widget.srl.RefreshingListenerAdapter)1 MaterialFooter (me.dkzwm.widget.srl.extra.footer.MaterialFooter)1 MaterialHeader (me.dkzwm.widget.srl.extra.header.MaterialHeader)1 HorizontalRecyclerViewAdapter (me.dkzwm.widget.srl.sample.adapter.HorizontalRecyclerViewAdapter)1