Advertisement
Guest User

Untitled

a guest
Dec 3rd, 2016
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.72 KB | None | 0 0
  1. Fragment fpoisk;
  2. Fragment fterritory;
  3.  
  4. Fragment fsovety;
  5.  
  6. @Override
  7. protected void onCreate(Bundle savedInstanceState) {
  8. super.onCreate(savedInstanceState);
  9. setContentView(R.layout.activity_main);
  10. Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
  11. setSupportActionBar(toolbar);
  12.  
  13.  
  14.  
  15. FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
  16. fab.setOnClickListener(new View.OnClickListener() {
  17. @Override
  18. public void onClick(View view) {
  19. Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
  20. .setAction("Action", null).show();
  21. }
  22. });
  23.  
  24. DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
  25. ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
  26. this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
  27. drawer.setDrawerListener(toggle);
  28. toggle.syncState();
  29.  
  30. NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
  31. navigationView.setNavigationItemSelectedListener(this);
  32.  
  33. fpoisk = new Fragment();
  34. fterritory = new Fragment();
  35. fsovety = new Fragment();
  36. }
  37.  
  38. @Override
  39. public void onBackPressed() {
  40. DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
  41. if (drawer.isDrawerOpen(GravityCompat.START)) {
  42. drawer.closeDrawer(GravityCompat.START);
  43. } else {
  44. super.onBackPressed();
  45. }
  46. }
  47.  
  48. @Override
  49. public boolean onCreateOptionsMenu(Menu menu) {
  50. getMenuInflater().inflate(R.menu.main, menu);
  51. return super.onCreateOptionsMenu(menu);
  52. }
  53.  
  54. @Override
  55. public boolean onOptionsItemSelected(MenuItem item) {
  56. int id = item.getItemId();
  57. if (id == R.id.soveti) {
  58. Intent intent = new Intent(this, PoleznieSovetiActivity.class);
  59. startActivity(intent);
  60. return true;
  61. }
  62.  
  63. return super.onOptionsItemSelected(item);
  64. }
  65.  
  66. @SuppressWarnings("StatementWithEmptyBody")
  67. @Override
  68. public boolean onNavigationItemSelected(MenuItem item) {
  69.  
  70. int id = item.getItemId();
  71.  
  72. FragmentTransaction ftrans = getFragmentManager().beginTransaction();
  73.  
  74. if (id == R.id.nav_territory) {
  75. ftrans.replace(R.id.content_main, fterritory);
  76. } else if (id == R.id.nav_sovety) {
  77. ftrans.replace(R.id.content_main, fsovety);
  78. } else if (id == R.id.nav_poisk) {
  79. ftrans.replace(R.id.content_main,fpoisk);
  80.  
  81. } else if (id == R.id.nav_share) {
  82.  
  83. } else if (id == R.id.nav_send) {
  84.  
  85. }
  86. ftrans.commit();
  87.  
  88. DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
  89. drawer.closeDrawer(GravityCompat.START);
  90. return true;
  91. }
  92.  
  93. @Override
  94. public void onStart() {
  95. super.onStart();
  96.  
  97. }
  98.  
  99. @Override
  100. public void onStop() {
  101. super.onStop();
  102.  
  103. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement