// Path: app/src/main/java/com/troy/xifan/adapter/MessagePagerAdapter.java
// public class MessagePagerAdapter extends FragmentPagerAdapter {
//     private List<Fragment> fragments;
//     private String[] tabTitles;
// 
//     public MessagePagerAdapter(FragmentManager fm, List<Fragment> fragments, String[] tabTitles) {
//         super(fm);
//         this.fragments = fragments;
//         this.tabTitles = tabTitles;
//     }
// 
//     @Override
//     public Fragment getItem(int position) {
//         return fragments.get(position);
//     }
// 
//     @Override
//     public int getCount() {
//         return fragments.size();
//     }
// 
//     @Override
//     public CharSequence getPageTitle(int position) {
//         return tabTitles[position];
//     }
// }


import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.support.v7.widget.Toolbar;
import butterknife.BindView;
import com.troy.xifan.R;
import com.troy.xifan.adapter.MessagePagerAdapter;
import java.util.ArrayList;
import java.util.List;
package com.troy.xifan.fragment;


/**
 * Created by chenlongfei on 2016/12/1.
 */

public class MessageFragment extends BaseFragment {
    @BindView(R.id.toolbar) Toolbar mToolbar;
    @BindView(R.id.tab_layout) TabLayout mTabLayout;
    @BindView(R.id.view_pager) ViewPager mViewPager;

    private List<Fragment> mFragments = new ArrayList<>();
    private String[] mTabTitles;

    public static Fragment newInstance() {
        return new MessageFragment();
    }

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        initFragments();
    }

    private void initFragments() {
        mFragments.add(MentionMessageFragment.newInstance());
        mFragments.add(DirectMessageFragment.newInstance());
    }

    @Override
    public void initViews() {
        mToolbar.setTitle(getString(R.string.title_message));
        mTabTitles = new String[] {
                getString(R.string.title_tab_mention_msg), getString(R.string.title_tab_direct_msg)
        };

        mTabLayout.setupWithViewPager(mViewPager);
        mViewPager.setOffscreenPageLimit(mTabTitles.length);
        mViewPager.setAdapter(
// Path: app/src/main/java/com/troy/xifan/adapter/MessagePagerAdapter.java
// public class MessagePagerAdapter extends FragmentPagerAdapter {
//     private List<Fragment> fragments;
//     private String[] tabTitles;
// 
//     public MessagePagerAdapter(FragmentManager fm, List<Fragment> fragments, String[] tabTitles) {
//         super(fm);
//         this.fragments = fragments;
//         this.tabTitles = tabTitles;
//     }
// 
//     @Override
//     public Fragment getItem(int position) {
//         return fragments.get(position);
//     }
// 
//     @Override
//     public int getCount() {
//         return fragments.size();
//     }
// 
//     @Override
//     public CharSequence getPageTitle(int position) {
//         return tabTitles[position];
//     }
// }


// Path: app/src/main/java/com/troy/xifan/fragment/MessageFragment.java
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.support.v7.widget.Toolbar;
import butterknife.BindView;
import com.troy.xifan.R;
import com.troy.xifan.adapter.MessagePagerAdapter;
import java.util.ArrayList;
import java.util.List;

package com.troy.xifan.fragment;


/**
 * Created by chenlongfei on 2016/12/1.
 */

public class MessageFragment extends BaseFragment {
    @BindView(R.id.toolbar) Toolbar mToolbar;
    @BindView(R.id.tab_layout) TabLayout mTabLayout;
    @BindView(R.id.view_pager) ViewPager mViewPager;

    private List<Fragment> mFragments = new ArrayList<>();
    private String[] mTabTitles;

    public static Fragment newInstance() {
        return new MessageFragment();
    }

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        initFragments();
    }

    private void initFragments() {
        mFragments.add(MentionMessageFragment.newInstance());
        mFragments.add(DirectMessageFragment.newInstance());
    }

    @Override
    public void initViews() {
        mToolbar.setTitle(getString(R.string.title_message));
        mTabTitles = new String[] {
                getString(R.string.title_tab_mention_msg), getString(R.string.title_tab_direct_msg)
        };

        mTabLayout.setupWithViewPager(mViewPager);
        mViewPager.setOffscreenPageLimit(mTabTitles.length);
        mViewPager.setAdapter(
                new MessagePagerAdapter(getChildFragmentManager(), mFragments, mTabTitles));