Guest User

Untitled

a guest
Oct 20th, 2018
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.43 KB | None | 0 0
  1. public class MainActivity extends AppCompatActivity {
  2. private SectionsPagerAdapter mSectionsPagerAdapter;
  3. private ViewPager mViewPager;
  4.  
  5. @Override
  6. protected void onCreate(Bundle savedInstanceState) {
  7. super.onCreate(savedInstanceState);
  8. setContentView(R.layout.activity_main);
  9. Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
  10. setSupportActionBar(toolbar);
  11. getSupportActionBar().setDisplayHomeAsUpEnabled(true);
  12. // Create the adapter that will return a fragment for each of the three
  13. // primary sections of the activity.
  14. mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager());
  15. mViewPager = (ViewPager) findViewById(R.id.container);
  16. mViewPager.setAdapter(mSectionsPagerAdapter);
  17.  
  18. TabLayout tabLayout = (TabLayout) findViewById(R.id.tabs);
  19.  
  20. mViewPager.addOnPageChangeListener(new TabLayout.TabLayoutOnPageChangeListener(tabLayout));
  21. tabLayout.addOnTabSelectedListener(new TabLayout.ViewPagerOnTabSelectedListener(mViewPager));
  22.  
  23.  
  24. }
  25.  
  26. public class SectionsPagerAdapter extends FragmentPagerAdapter {
  27. public SectionsPagerAdapter(FragmentManager fm) {
  28. super(fm);
  29. }
  30.  
  31. @Override
  32. public Fragment getItem(int position) {
  33. switch (position)
  34. {
  35. case 0 : Summary summary = new Summary(); return summary ;
  36. case 1 : Expense_items expenseItems = new Expense_items(); return expenseItems;
  37. case 2 : Linage_items linage_items= new Linage_items(); return linage_items;
  38. default: return null;
  39. }
  40. }
  41.  
  42. @Override
  43. public int getCount() {
  44. // Show 3 total pages.
  45. return 3;
  46. }
  47. }
  48. }
  49.  
  50. public class Summary extends Fragment {
  51. @Override
  52. public View onCreateView(LayoutInflater inflater, ViewGroup container,
  53. Bundle savedInstanceState) {
  54. View rootView = inflater.inflate(R.layout.fragment_summary, container, false);
  55. TextView summary_text = (TextView) rootView.findViewById(R.id.summary_text);
  56. summary_text.setText("You are in Summary Fragment Fragment");
  57. FloatingActionButton myFB = (FloatingActionButton) rootView.findViewById(R.id.fab);
  58.  
  59. return rootView;
  60. }
  61. }
  62.  
  63. <android.support.design.widget.FloatingActionButton
  64. android:id="@+id/Main_FAB"
  65. android:layout_width="wrap_content"
  66. android:layout_height="wrap_content"
  67. android:layout_gravity="end|bottom"
  68. android:layout_margin="@dimen/fab_margin"
  69. app:srcCompat="@android:drawable/ic_dialog_email" />
Add Comment
Please, Sign In to add comment