Search in sources :

Example 1 with RecentPostsFragment

use of com.google.firebase.quickstart.database.fragment.RecentPostsFragment in project quickstart-android by firebase.

the class MainActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    // 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(MainActivity.this, NewPostActivity.class));
        }
    });
}
Also used : FragmentPagerAdapter(android.support.v4.app.FragmentPagerAdapter) Intent(android.content.Intent) RecentPostsFragment(com.google.firebase.quickstart.database.fragment.RecentPostsFragment) Fragment(android.support.v4.app.Fragment) MyPostsFragment(com.google.firebase.quickstart.database.fragment.MyPostsFragment) MyTopPostsFragment(com.google.firebase.quickstart.database.fragment.MyTopPostsFragment) View(android.view.View) MyTopPostsFragment(com.google.firebase.quickstart.database.fragment.MyTopPostsFragment) RecentPostsFragment(com.google.firebase.quickstart.database.fragment.RecentPostsFragment) TabLayout(android.support.design.widget.TabLayout) MyPostsFragment(com.google.firebase.quickstart.database.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.google.firebase.quickstart.database.fragment.MyPostsFragment)1 MyTopPostsFragment (com.google.firebase.quickstart.database.fragment.MyTopPostsFragment)1 RecentPostsFragment (com.google.firebase.quickstart.database.fragment.RecentPostsFragment)1