Search in sources :

Example 1 with SampleRecyclerAdapter

use of me.relex.circleindicator.sample.SampleRecyclerAdapter 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)

Example 2 with SampleRecyclerAdapter

use of me.relex.circleindicator.sample.SampleRecyclerAdapter in project CircleIndicator by ongakuer.

the class RecyclerViewFragment method onViewCreated.

@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
    mAdapter = new SampleRecyclerAdapter(5);
    RecyclerView recyclerView = view.findViewById(R.id.recycler_view);
    LinearLayoutManager layoutManager = new LinearLayoutManager(getContext(), LinearLayoutManager.HORIZONTAL, false);
    recyclerView.setLayoutManager(layoutManager);
    recyclerView.setAdapter(mAdapter);
    PagerSnapHelper pagerSnapHelper = new PagerSnapHelper();
    pagerSnapHelper.attachToRecyclerView(recyclerView);
    // CircleIndicator2 for RecyclerView
    CircleIndicator2 indicator = view.findViewById(R.id.indicator);
    indicator.attachToRecyclerView(recyclerView, pagerSnapHelper);
    // Scroll To Position
    layoutManager.scrollToPosition(2);
    // 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 : CircleIndicator2(me.relex.circleindicator.CircleIndicator2) SampleRecyclerAdapter(me.relex.circleindicator.sample.SampleRecyclerAdapter) PagerSnapHelper(androidx.recyclerview.widget.PagerSnapHelper) RecyclerView(androidx.recyclerview.widget.RecyclerView) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView)

Aggregations

View (android.view.View)2 SampleRecyclerAdapter (me.relex.circleindicator.sample.SampleRecyclerAdapter)2 LinearLayoutManager (androidx.recyclerview.widget.LinearLayoutManager)1 PagerSnapHelper (androidx.recyclerview.widget.PagerSnapHelper)1 RecyclerView (androidx.recyclerview.widget.RecyclerView)1 ViewPager2 (androidx.viewpager2.widget.ViewPager2)1 CircleIndicator2 (me.relex.circleindicator.CircleIndicator2)1 CircleIndicator3 (me.relex.circleindicator.CircleIndicator3)1