kaveer
9/18/2016 - 4:55 PM

Navigate to activity and fragment

Navigate to activity and fragment

VehicleDetailsFragment fragment = new VehicleDetailsFragment();
android.support.v4.app.FragmentTransaction fmTransaction = getFragmentManager().beginTransaction();
fmTransaction.replace(R.id.Frame_container, fragment);
fmTransaction.commit();

//where VehicleDetailsFragment  is the name of the java file
// where R.id.Frame_container is the id of the framelayout in app_bar.xml
 <FrameLayout
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:id="@+id/Frame_container"></FrameLayout>
      
//Add the above code this in file res/layout/activity_bar_APPNAME.xml and remove include....
//in main activity code behind execute the following code

public boolean onNavigationItemSelected(MenuItem item) {
        int id = item.getItemId();
        if (id == R.id.NavVehicleDetails) {
            VehicleDetailsFragment fragment = new  VehicleDetailsFragment();
            android.support.v4.app.FragmentTransaction fmTransaction = getSupportFragmentManager().beginTransaction();
            fmTransaction.replace(R.id.Frame_container, fragment);
            fmTransaction.commit();
        } else if (id == R.id.NavHome) {
            MainFragment fragment = new MainFragment();
            android.support.v4.app.FragmentTransaction fmTransaction = getSupportFragmentManager().beginTransaction();
            fmTransaction.replace(R.id.Frame_container, fragment);
            fmTransaction.commit();
        }
}

//where VehicleDetailsFragment is the fragment that user wants to navigate
// fmTransaction.replace(R.id.Frame_container, fragment); replace actual fragment to object fragment of class VehicleDetailsFragments

 Intent i = new Intent(SignUp.this, VMS.class);
                startActivity(i);
                

  //where SignUp.this is the current activity and VMS.class is the acivity that the user want to navigate to