Search in sources :

Example 1 with CircleIndicator3

use of me.relex.circleindicator.CircleIndicator3 in project CircleIndicator by ongakuer.

the class ViewPager2Fragment method onViewCreated.

@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
    mAdapter = new SampleRecyclerAdapter(5);
    ViewPager2 viewpager = view.findViewById(R.id.viewpager);
    viewpager.setAdapter(mAdapter);
    // CircleIndicator3 for RecyclerView
    CircleIndicator3 indicator = view.findViewById(R.id.indicator);
    indicator.setViewPager(viewpager);
    // CurrentItem
    viewpager.setCurrentItem(2, false);
    // Observe Data Change
    mAdapter.registerAdapterDataObserver(indicator.getAdapterDataObserver());
    view.findViewById(R.id.add).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            mAdapter.add();
        }
    });
    view.findViewById(R.id.remove).setOnClickListener(v -> {
        mAdapter.remove();
    });
}
Also used : ViewPager2(androidx.viewpager2.widget.ViewPager2) CircleIndicator3(me.relex.circleindicator.CircleIndicator3) SampleRecyclerAdapter(me.relex.circleindicator.sample.SampleRecyclerAdapter) View(android.view.View)

Aggregations

View (android.view.View)1 ViewPager2 (androidx.viewpager2.widget.ViewPager2)1 CircleIndicator3 (me.relex.circleindicator.CircleIndicator3)1 SampleRecyclerAdapter (me.relex.circleindicator.sample.SampleRecyclerAdapter)1