0

On the new support design library I cant replace current fragment, check my code below. Although the Toasts are working and displaying on the screen. I'm getting empty screen whenever I'm going to click on any item on the navigation drawer

private void setupDrawerContent(NavigationView navigationView) {
    navigationView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() {
        @Override
        public boolean onNavigationItemSelected(MenuItem menuItem) {
            switch (menuItem.getItemId()) {
                case R.id.navigation_home:
                    getFragmentManager().beginTransaction().replace(R.id.container, new HomeFragment()).commit();
                    Toast toast;
                    toast = Toast.makeText(getApplicationContext(), "Home", Toast.LENGTH_LONG);
                    toast.show();

                case R.id.navigation_settings:
                    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
                        getFragmentManager().beginTransaction().replace(R.id.container, new SettingsFragmentLollipop()).commit();
                    } else {
                        getFragmentManager().beginTransaction().replace(R.id.container, new SettingsFragment()).commit();
                    }
                    Toast toast1;
                    toast1 = Toast.makeText(getApplicationContext(), "Settings", Toast.LENGTH_LONG);
                    toast1.show();
            }
            menuItem.setChecked(true);
            mDrawerLayout.closeDrawers();
            return true;
        }
    });
}
ponnex
  • 838
  • 5
  • 18

2 Answers2

1

Okay I got it working, I feel stupid after hours of back tracking of what is wrong with my code. in my xml, I use android.support.design.widget.CoordinatorLayout for the Fragment container in which I replace it back with a FrameLayout. I did that cause in the document it says that CoordinatorLayout is just a super FrameLayout but I guess it won't work as container for Fragments. I am now dealing with overlapping fragments.

ponnex
  • 838
  • 5
  • 18
0

Try, if using class AppCompatActivity

getSupportFragmentManager().beginTransaction().replace(R.id.container,  new HomeFragment()).commit();

I'm just playing around with new library myself

RuAware
  • 979
  • 1
  • 9
  • 26
  • I'm using PreferenceFragment on the `SettingsFragmentLollipop()` and `SettingsFragment()` so using `getSupportFragmentManager()` won't work only `getFragmentManager()` – ponnex May 31 '15 at 05:36