Search in sources :

Example 1 with ViewPagerIndicator

use of carbon.widget.ViewPagerIndicator in project Carbon by ZieIony.

the class TabsActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    initToolbar();
    ViewPager pager = findViewById(R.id.pager);
    pager.setAdapter(new PagerAdapter() {

        @Override
        public CharSequence getPageTitle(int position) {
            return "Page " + position;
        }

        View getView(int position, ViewPager pager) {
            return new RelativeLayout(pager.getContext(), null, R.attr.carbon_cardViewStyle);
        }

        @Override
        public boolean isViewFromObject(@NonNull View view, @NonNull Object object) {
            return view == object;
        }

        @Override
        public int getCount() {
            return 7;
        }

        @NonNull
        @Override
        public Object instantiateItem(@NonNull ViewGroup container, int position) {
            ViewPager pager = (ViewPager) container;
            View view = getView(position, pager);
            pager.addView(view);
            return view;
        }

        @Override
        public void destroyItem(@NonNull ViewGroup container, int position, @NonNull Object view) {
            container.removeView((View) view);
        }
    });
    TabLayout tabs = findViewById(R.id.tabs);
    tabs.setViewPager(pager);
    ViewPagerIndicator indicator = findViewById(R.id.indicator);
    indicator.setViewPager(pager);
}
Also used : ViewGroup(android.view.ViewGroup) TabLayout(carbon.widget.TabLayout) ViewPagerIndicator(carbon.widget.ViewPagerIndicator) NonNull(androidx.annotation.NonNull) RelativeLayout(carbon.widget.RelativeLayout) ViewPager(carbon.widget.ViewPager) View(android.view.View) PagerAdapter(androidx.viewpager.widget.PagerAdapter)

Aggregations

View (android.view.View)1 ViewGroup (android.view.ViewGroup)1 NonNull (androidx.annotation.NonNull)1 PagerAdapter (androidx.viewpager.widget.PagerAdapter)1 RelativeLayout (carbon.widget.RelativeLayout)1 TabLayout (carbon.widget.TabLayout)1 ViewPager (carbon.widget.ViewPager)1 ViewPagerIndicator (carbon.widget.ViewPagerIndicator)1