Android Open Source - Android-Navigation-Drawer-with-Tabs Fragment Main2






From Project

Back to project page Android-Navigation-Drawer-with-Tabs.

License

The source code is released under:

Apache License

If you think the Android project Android-Navigation-Drawer-with-Tabs listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.example.navigationdrawertest;
//  w  w w .j  a v a 2s.  co  m
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentStatePagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

public class FragmentMain2 extends Fragment {

  private ViewPager viewPager;

  @Override
  public void onViewCreated(View view, Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);
  }

  public FragmentMain2() {
    // Required empty public constructor
  }

  @Override
  public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);

    viewPager = (ViewPager) getView().findViewById(R.id.pager);
    viewPager.setAdapter(new MyAdapter2(getFragmentManager()));
  }

  @Override
  public View onCreateView(LayoutInflater inflater, ViewGroup container,
      Bundle savedInstanceState) {
    // Inflate the layout for this fragment
    return inflater.inflate(R.layout.fragment_main_2, container, false);
  }
}

class MyAdapter2 extends FragmentStatePagerAdapter {

  public MyAdapter2(FragmentManager fm) {
    super(fm);
  }

  @Override
  public Fragment getItem(int arg0) {
    Fragment fragment = null;
    if (arg0 == 0) {
      fragment = new Home5();
    }
    if (arg0 == 1) {
      fragment = new Home6();
    }
    if (arg0 == 2) {
      fragment = new Home7();
    }
    if (arg0 == 3) {
      fragment = new Home8();
    }
    return fragment;
  }

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

  @Override
  public CharSequence getPageTitle(int position) {
    if (position == 0) {
      return "Home Tab 5";
    }
    if (position == 1) {
      return "Home Tab 6";
    }
    if (position == 2) {
      return "Home Tab 7";
    }
    if (position == 3) {
      return "Home Tab 8";
    }
    return null;
  }
}




Java Source Code List

com.example.navigationdrawertest.FragmentMain2.java
com.example.navigationdrawertest.FragmentMain.java
com.example.navigationdrawertest.Home1.java
com.example.navigationdrawertest.Home2.java
com.example.navigationdrawertest.Home3.java
com.example.navigationdrawertest.Home4.java
com.example.navigationdrawertest.Home5.java
com.example.navigationdrawertest.Home6.java
com.example.navigationdrawertest.Home7.java
com.example.navigationdrawertest.Home8.java
com.example.navigationdrawertest.MainActivity.java