SHARE
TWEET

MainActivity.java

ceikdo Aug 19th, 2019 (edited) 73 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package com.example.moviecataloguesub2;
  2.  
  3. import android.os.Bundle;
  4. import android.support.annotation.NonNull;
  5. import android.support.design.widget.BottomNavigationView;
  6. import android.support.v4.app.Fragment;
  7. import android.support.v7.app.AppCompatActivity;
  8. import android.view.MenuItem;
  9.  
  10. public class MainActivity extends AppCompatActivity {
  11.  
  12.  
  13.     private BottomNavigationView.OnNavigationItemSelectedListener mOnNavigationItemSelectedListener
  14.             = new BottomNavigationView.OnNavigationItemSelectedListener() {
  15.  
  16.         @Override
  17.         public boolean onNavigationItemSelected(@NonNull MenuItem item) {
  18.             Fragment fragment;
  19.  
  20.             switch (item.getItemId()) {
  21.                 case R.id.navigation_movie:
  22.                     fragment = new MovieFragment();
  23.                     getSupportFragmentManager().beginTransaction().replace(R.id.container_layout, fragment, fragment.getClass().getSimpleName()).commit();
  24.                     return true;
  25.  
  26.                 case R.id.navigation_tv_show:
  27.                     fragment = new TvShowFragment();
  28.                     getSupportFragmentManager().beginTransaction().replace(R.id.container_layout, fragment, fragment.getClass().getSimpleName()).commit();
  29.                     return true;
  30.  
  31.             }
  32.             return false;
  33.         }
  34.     };
  35.  
  36.     @Override
  37.     protected void onCreate(Bundle savedInstanceState) {
  38.         super.onCreate(savedInstanceState);
  39.         setContentView(R.layout.activity_main);
  40.  
  41.         BottomNavigationView navView = findViewById(R.id.nav_view);
  42.         navView.setOnNavigationItemSelectedListener(mOnNavigationItemSelectedListener);
  43.  
  44.         if (savedInstanceState == null) {
  45.             navView.setSelectedItemId(R.id.navigation_movie);
  46.         }
  47.     }
  48.  
  49.  
  50. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top