Search in sources :

Example 1 with RecentPostsFragment

use of com.example.management.fragment.RecentPostsFragment in project priend by TakoJ.

the class CommunityActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_community);
    // Create the adapter that will return a fragment for each section
    mPagerAdapter = new FragmentPagerAdapter(getSupportFragmentManager()) {

        private final Fragment[] mFragments = new Fragment[] { new RecentPostsFragment(), new MyPostsFragment(), new MyTopPostsFragment() };

        private final String[] mFragmentNames = new String[] { getString(R.string.heading_recent), getString(R.string.heading_my_posts), getString(R.string.heading_my_top_posts) };

        @Override
        public Fragment getItem(int position) {
            return mFragments[position];
        }

        @Override
        public int getCount() {
            return mFragments.length;
        }

        @Override
        public CharSequence getPageTitle(int position) {
            return mFragmentNames[position];
        }
    };
    // Set up the ViewPager with the sections adapter.
    mViewPager = (ViewPager) findViewById(R.id.container);
    mViewPager.setAdapter(mPagerAdapter);
    TabLayout tabLayout = (TabLayout) findViewById(R.id.tabs);
    tabLayout.setupWithViewPager(mViewPager);
    // Button launches NewPostActivity
    findViewById(R.id.fab_new_post).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            startActivity(new Intent(CommunityActivity.this, NewPostActivity.class));
        }
    });
}
Also used : FragmentPagerAdapter(android.support.v4.app.FragmentPagerAdapter) Intent(android.content.Intent) Fragment(android.support.v4.app.Fragment) MyTopPostsFragment(com.example.management.fragment.MyTopPostsFragment) RecentPostsFragment(com.example.management.fragment.RecentPostsFragment) MyPostsFragment(com.example.management.fragment.MyPostsFragment) View(android.view.View) MyTopPostsFragment(com.example.management.fragment.MyTopPostsFragment) RecentPostsFragment(com.example.management.fragment.RecentPostsFragment) TabLayout(android.support.design.widget.TabLayout) MyPostsFragment(com.example.management.fragment.MyPostsFragment)

Aggregations

Intent (android.content.Intent)1 TabLayout (android.support.design.widget.TabLayout)1 Fragment (android.support.v4.app.Fragment)1 FragmentPagerAdapter (android.support.v4.app.FragmentPagerAdapter)1 View (android.view.View)1 MyPostsFragment (com.example.management.fragment.MyPostsFragment)1 MyTopPostsFragment (com.example.management.fragment.MyTopPostsFragment)1 RecentPostsFragment (com.example.management.fragment.RecentPostsFragment)1