Search in sources :

Example 1 with NestedPageFragment

use of me.dkzwm.widget.srl.sample.ui.fragment.NestedPageFragment in project SmoothRefreshLayout by dkzwm.

the class TestNestedWithViewPagerActivity method onCreate.

@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_test_nested_with_viewpager);
    final Toolbar toolbar = findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    toolbar.setNavigationIcon(R.drawable.arrow_back_white_72x72);
    toolbar.setNavigationOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            onBackPressed();
        }
    });
    ViewPager viewPager = findViewById(R.id.viewPager_test_nested_with_viewPager);
    mFragments = new ArrayList<>();
    for (int sColor : sColors) {
        mFragments.add(NestedPageFragment.newInstance(sColor));
    }
    ViewPagerAdapter adapter = new ViewPagerAdapter(getSupportFragmentManager(), mFragments);
    viewPager.setAdapter(adapter);
    mRefreshLayout = findViewById(R.id.smoothRefreshLayout_test_nested_with_viewPager);
    mRefreshLayout.setDisableLoadMore(false);
    mRefreshLayout.materialStyle();
    mRefreshLayout.setOnRefreshListener(new SmoothRefreshLayout.OnRefreshListener() {

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

                @Override
                public void run() {
                    for (int i = 0; i < mFragments.size(); i++) {
                        NestedPageFragment fragment = mFragments.get(i);
                        fragment.updateData();
                    }
                    mRefreshLayout.refreshComplete();
                }
            }, 2000);
        }

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

                @Override
                public void run() {
                    for (int i = 0; i < mFragments.size(); i++) {
                        NestedPageFragment fragment = mFragments.get(i);
                        fragment.appendData();
                    }
                    mRefreshLayout.refreshComplete();
                }
            }, 2000);
        }
    });
    mRefreshLayout.setDisableWhenAnotherDirectionMove(true);
    mRefreshLayout.autoRefresh(false);
}
Also used : NestedPageFragment(me.dkzwm.widget.srl.sample.ui.fragment.NestedPageFragment) ViewPagerAdapter(me.dkzwm.widget.srl.sample.adapter.ViewPagerAdapter) View(android.view.View) ViewPager(androidx.viewpager.widget.ViewPager) Toolbar(androidx.appcompat.widget.Toolbar) MaterialSmoothRefreshLayout(me.dkzwm.widget.srl.MaterialSmoothRefreshLayout) SmoothRefreshLayout(me.dkzwm.widget.srl.SmoothRefreshLayout)

Aggregations

View (android.view.View)1 Toolbar (androidx.appcompat.widget.Toolbar)1 ViewPager (androidx.viewpager.widget.ViewPager)1 MaterialSmoothRefreshLayout (me.dkzwm.widget.srl.MaterialSmoothRefreshLayout)1 SmoothRefreshLayout (me.dkzwm.widget.srl.SmoothRefreshLayout)1 ViewPagerAdapter (me.dkzwm.widget.srl.sample.adapter.ViewPagerAdapter)1 NestedPageFragment (me.dkzwm.widget.srl.sample.ui.fragment.NestedPageFragment)1