Advertisement
Guest User

Untitled

a guest
Jul 23rd, 2017
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.25 KB | None | 0 0
  1. public class homeTabsAdapter extends FragmentPagerAdapter implements PagerSlidingTabStrip.IconTabProvider {
  2. /**
  3. * Contains all the fragments.
  4. */
  5. private int tabIcons[] = {R.drawable.requests, R.drawable.connections, R.drawable.messages};
  6.  
  7. private List<Fragment> fragments = new ArrayList<>();
  8.  
  9. /**
  10. * Contains all the tab titles.
  11. */
  12. private List<String> tabTitles = new ArrayList<>();
  13.  
  14. /**
  15. * Creates a new PagerAdapter instance.
  16. *
  17. * @param fragmentManager The FragmentManager.
  18. */
  19. public homeTabsAdapter(FragmentManager fragmentManager) {
  20. super(fragmentManager);
  21. }
  22.  
  23. @Override
  24. public int getCount() {
  25. return fragments.size();
  26. }
  27.  
  28. @Override
  29. public Fragment getItem(int position) {
  30. return fragments.get(position);
  31. }
  32.  
  33. @Override
  34. public int getPageIconResId(int position) {
  35. return tabIcons[position];
  36. }
  37.  
  38. @Override
  39. public CharSequence getPageTitle(int position) {
  40. return tabTitles.get(position);
  41. }
  42.  
  43. /**
  44. * Adds the fragment to the list, also adds the fragment's tab title.
  45. *
  46. * @param fragment New instance of the Fragment to be associated with this tab.
  47. * @param tabTitle A String containing the tab title for this Fragment.
  48. */
  49. public void addFragment(Fragment fragment, String tabTitle) {
  50. fragments.add(fragment);
  51. tabTitles.add(tabTitle);
  52. }
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement