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






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  2 s .  com*/
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 FragmentMain extends Fragment {

  private ViewPager viewPager;

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

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

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

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

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

class MyAdapter extends FragmentStatePagerAdapter {

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

  @Override
  public Fragment getItem(int arg0) {
    Fragment fragment = null;
    if (arg0 == 0) {
      fragment = new Home1();
    }
    if (arg0 == 1) {
      fragment = new Home2();
    }
    if (arg0 == 2) {
      fragment = new Home3();
    }
    if (arg0 == 3) {
      fragment = new Home4();
    }
    return fragment;
  }

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

  @Override
  public CharSequence getPageTitle(int position) {
    if (position == 0) {
      return "Home Tab 1";
    }
    if (position == 1) {
      return "Home Tab 2";
    }
    if (position == 2) {
      return "Home Tab 3";
    }
    if (position == 3) {
      return "Home Tab 4";
    }
    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