If you are not read yet the part-07 blog then first of all you read and implement part-07 visit CLICK HERE also you can watch our YouTube video Click Here.

In this blog, we can create a ViewPagerAdapter file that will help to implement both Fragment pages in one Activity. So if you are not able to create a new page then follow our Instruction given below.

  1. Your project must be open with Android Type.
  2. Double click the java file and select your package name project.
  3. Right-click on the java file go to New and select Java Class.
  4. Under ViewPagerAdapter class we can implement the remaining code for ViewPager use purposes.

After successfully created a ViewPagerAdapter java class then we have to extends with FragmentPagerAdapter code and image given below for your better understanding.

public class ViewPagerAdapter extends FragmentPagerAdapter

Now, we can write variable for showing in ViewPager Layout.

private final List<Fragment> fragmentName = new ArrayList<>();
private final List<String> fragmentTitle = new ArrayList<>();

Next, we can create a Constructor class you can use the shortcut method press the Alt+Insert Button of your keyboard.

// Constructor
public ViewPagerAdapter(@NonNull FragmentManager fm) {

Next, Below constructor create a getItem method class.

public Fragment getItem(int position) {
return fragmentName.get(position);

Next, Below getItem create a getCount method class.

public int getCount() {
return fragmentTitle.size();

Next, we create a getPageTitle class below getCount.

public CharSequence getPageTitle(int position) {
return fragmentTitle.get(position);

And last, we create a AddFragment class below getPageTitle class.

// Add Fragment Manager
public void AddFragment(Fragment fragment, String title) {

We created ViewPagerAdapter successfully So in the Next part we work on MainActivity.java Class for the complete step. Want to learn the next part CLICK HERE.


Leave a Reply

Your email address will not be published. Required fields are marked *