0% found this document useful (0 votes)
5 views1 page

On Create

The document outlines the process of creating a ViewPager and setting its adapter and initial item. It also describes how to define a TabLayout, associate it with the ViewPager, and add it to an AppBarLayout that contains a ToolBar. Finally, it mentions adding the ViewPager to a linear layout in the main XML file.

Uploaded by

dimsbro0
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views1 page

On Create

The document outlines the process of creating a ViewPager and setting its adapter and initial item. It also describes how to define a TabLayout, associate it with the ViewPager, and add it to an AppBarLayout that contains a ToolBar. Finally, it mentions adding the ViewPager to a linear layout in the main XML file.

Uploaded by

dimsbro0
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

// Create a ViewPager, set adapter for it, and set it's current item to position 0

(page0.xml).
androidx.viewpager.widget.ViewPager viewPager1 = new
androidx.viewpager.widget.ViewPager(this);
viewPager1.setAdapter(new MyPagerAdapter());
viewPager1.setCurrentItem(0);

// Define a new TabLayout, set it up with the ViewPager, and add it to the
AppBarLayout which surrounds the ToolBar. The AppBarLayout thus will contain
ToolBar and TabLayout.
com.google.android.material.tabs.TabLayout tabLayout = new
com.google.android.material.tabs.TabLayout(this);
tabLayout.setTabMode(com.google.android.material.tabs.TabLayout.MODE_SCROLLABLE);

tabLayout.setupWithViewPager(viewPager1);
((com.google.android.material.appbar.AppBarLayout)_toolbar.getParent()).addView(tab
Layout);
// Add the ViewPager to linear1 of main.xml
linear1.addView(viewPager1);

You might also like