narimetisaigopi

TabViewPagerAdapter.java tablayout

Feb 11th, 2020
177
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.42 KB | None | 0 0
  1. package com.example.saigopinarimeti.helloworld.Adapters;
  2.  
  3. import android.support.annotation.Nullable;
  4. import android.support.v4.app.Fragment;
  5. import android.support.v4.app.FragmentManager;
  6. import android.support.v4.app.FragmentPagerAdapter;
  7. import android.support.v4.view.PagerAdapter;
  8.  
  9. import com.example.saigopinarimeti.helloworld.fragments.AFragment;
  10. import com.example.saigopinarimeti.helloworld.fragments.BFragment;
  11. import com.example.saigopinarimeti.helloworld.fragments.CFragment;
  12.  
  13. public class TabViewPagerAdapter extends FragmentPagerAdapter {
  14.  
  15. public TabViewPagerAdapter(FragmentManager fm) {
  16. super(fm);
  17. }
  18.  
  19. @Override
  20. public Fragment getItem(int position) {
  21. Fragment fragment = null;
  22. if (position == 0){
  23. fragment = new AFragment();
  24. }
  25.  
  26. if (position == 1){
  27. fragment = new BFragment();
  28. }
  29.  
  30. if (position == 2){
  31. fragment = new CFragment();
  32. }
  33. return fragment;
  34. }
  35.  
  36. @Override
  37. public int getCount() {
  38. return 3;
  39. }
  40.  
  41. @Nullable
  42. @Override
  43. public CharSequence getPageTitle(int position) {
  44. String title = "";
  45. if (position == 0){
  46. title = "A Tab";
  47. }
  48. if (position == 1){
  49. title = "B Tab";
  50. }
  51. if (position == 2){
  52. title = "C Tab";
  53. }
  54. return title;
  55. }
  56. }
Add Comment
Please, Sign In to add comment