I am trying to set which fragment should be displayed first on start up. To determine this I check whether the user is logged in with ParseUser.getCurrentUser() and if a fil
To handle the default selection of the fragment in Your MainActivity
, you need to do the following:
MainActivity
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); mNavigationDrawerFragment = (NavigationDrawerFragment) getSupportFragmentManager().findFragmentById(R.id.navigation_drawer); mTitle = getTitle(); int selectedSection = getIntent().getIntExtra(EXTRA_PARAMS_ID, 0); // Set up the drawer. mNavigationDrawerFragment.setUp( R.id.navigation_drawer, (DrawerLayout) findViewById(R.id.drawer_layout), selectedSection); mNavigationDrawerFragment.selectItem(selectedSection); } @Override public void onNavigationDrawerItemSelected(int position) { // update the main content by replacing fragments // You could switch over different positions to show the right fragment FragmentManager fragmentManager = getSupportFragmentManager(); fragmentManager.beginTransaction() .replace(R.id.container, YourFragment.newInstance(position)) .commit(); } public void onSectionAttached(int position) { final String[] sections = getResources().getStringArray(R.array.sections); if (sections.length > position) mTitle = sections[position]; getSupportActionBar().setTitle(mTitle); }
NavigationDrawerFragment
remove the selectItem(mCurrentSelectedPosition);
from the onCreate()