Created
November 11, 2015 03:16
-
-
Save manishkpr/80ee2257a38108c8a8e5 to your computer and use it in GitHub Desktop.
Android Material Tabs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.webheavens.manishkprmaterialtabs.adapters; | |
import android.support.v4.app.Fragment; | |
import android.support.v4.app.FragmentManager; | |
import android.support.v4.app.FragmentStatePagerAdapter; | |
import com.webheavens.manishkprmaterialtabs.fragments.PostsFragment; | |
/** | |
* Created by Munish on 10/15/15. | |
*/ | |
public class MainPagerAdapter extends FragmentStatePagerAdapter { | |
CharSequence Titles[]; // This will Store the Titles of the Tabs which are Going to be passed when ViewPagerAdapter is created | |
int NumbOfTabs; // Store the number of tabs, this will also be passed when the ViewPagerAdapter is created | |
// Build a Constructor and assign the passed Values to appropriate values in the class | |
public MainPagerAdapter(FragmentManager fm, CharSequence mTitles[], int mNumbOfTabsumb) { | |
super(fm); | |
this.Titles = mTitles; | |
this.NumbOfTabs = mNumbOfTabsumb; | |
} | |
//This method return the fragment for the every position in the View Pager | |
@Override | |
public Fragment getItem(int position) { | |
if(position == 0) // if the position is 0 we are returning the First tab | |
{ | |
PostsFragment tab1 = new PostsFragment(); | |
return tab1; | |
} | |
else // As we are having 2 tabs if the position is now 0 it must be 1 so we are returning second tab | |
{ | |
PostsFragment tab2 = new PostsFragment(); | |
return tab2; | |
} | |
} | |
// This method return the titles for the Tabs in the Tab Strip | |
@Override | |
public CharSequence getPageTitle(int position) { | |
return Titles[position]; | |
} | |
// This method return the Number of tabs for the tabs Strip | |
@Override | |
public int getCount() { | |
return NumbOfTabs; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment