title: replace login fragment by home fragment
body: <p>I am novice in programming android j would like to work with fragments but we want to replace the fragment login by the fragment home when we click on connection j can not get any idea</p>
  
  <p>I have to try a lot of technique but I can not get what I want</p>
  
  <p>here is what i have as a code.
  Class MainActivity :</p>
  
  <pre><code>package com.cuveri.mobile.vue;
  import android.app.ProgressDialog;
  import android.content.Intent;
  import android.os.Bundle;
  import android.support.annotation.Nullable;
  import android.support.v4.app.FragmentActivity;
  import android.widget.TextView;
  import android.widget.*;
  import com.cuveri.mobile.controleur.LoginFragment;
  import com.example.symameri.mhis.R;
  import static com.example.symameri.mhis.R.layout.activity_Main;
  public class MainActivity extends FragmentActivity{
  
  
  @Override
  protected void onCreate(@Nullable Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(activity_Main);
      LoginFragment fragment = (LoginFragment) getFragmentManager().
              findFragmentById(R.id.logFragment);
  
  
  
  
  
  
  }
  
  
  
  
  
  /* public void navigatetoHomeActivity(){
      Intent homeIntent = new 
  Intent(getApplicationContext(),HomeActivity.class);
      homeIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
      startActivity(homeIntent);
      finish();
  }*/
  
  }
  </code></pre>
  
  <p>Layout actuvity_Main:</p>
  
  <pre><code> &lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;RelativeLayout xmlns:android = "http://schemas.android.com/apk/res/android"
  xmlns:tools = "http://schemas.android.com/tools" 
  android:layout_width="match_parent"
  android:layout_height = "match_parent" android:paddingLeft= 
  "@android:dimen/app_icon_size"
  android:paddingRight="@android:dimen/app_icon_size"
  android:paddingTop="@android:dimen/app_icon_size"
  android:paddingBottom = "@android:dimen/app_icon_size" tools:context = 
  "com.cuveri.mobile.vue.MainActivity"
  android:background="#e2dfdf"&gt;
  
  &lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;fragment
      android:id="@+id/logFragment"
      xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:name="com.cuveri.mobile.controleur.LoginFragment"/&gt;
  
  &lt;fragment
      android:id="@+id/hFragment"
      xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:name="com.cuveri.mobile.controleur.HomeFragment"/&gt;
  
  &lt;/RelativeLayout&gt;
  </code></pre>
  
  <p>Class Login_Fragment</p>
  
  <pre><code>package com.cuveri.mobile.controleur;
  
  
  import android.app.Fragment;
  import android.app.ProgressDialog;
  import android.os.*;
  
  import android.support.annotation.Nullable;
  import android.view.LayoutInflater;
  import android.view.*;
  import android.view.ViewGroup;
  import android.widget.Button;
   import android.widget.EditText;
   import android.widget.TextView;
  
  import com.cuveri.mobile.vue.MainActivity;
  import com.example.symameri.mhis.R;
  
  import java.io.IOException;
  
  import ca.mimic.oauth2library.OAuth2Client;
  import ca.mimic.oauth2library.OAuthError;
  import ca.mimic.oauth2library.OAuthResponse;
  
  public class LoginFragment extends Fragment{
  //code le comportement du login
  ProgressDialog prgDialog;
  TextView errorMsg;
  EditText identify;
  EditText password;
  Button connexion;
  
  @Override
  public void onCreate(@Nullable Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
  
  }
  
  @Nullable
  @Override
  public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup 
  container, Bundle savedInstanceState) {
      return inflater.inflate(R.layout.login_fragment, container, false);
  }
  
  @Override
  public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
      errorMsg = (TextView) view.findViewById(R.id.login_error);
      password =(EditText) view.findViewById(R.id.Mot_de_passe);
      identify=(EditText) view.findViewById(R.id.Identifiant);
      connexion =(Button) view.findViewById(R.id.button_connexion) ;
  
      if (android.os.Build.VERSION.SDK_INT &gt; 9)
      {
          StrictMode.ThreadPolicy policy = new 
      StrictMode.ThreadPolicy.Builder().permitAll().build();
          StrictMode.setThreadPolicy(policy);
      }
      }
      public void loginUser (View view) {
      String username = identify.getText().toString();
      String passwords = password.getText().toString();
  
  
      OAuth2Client client = new OAuth2Client.Builder("macuverie_mobile", 
  "appmobile", "http://10.0.2.2:8080/oauth/token")
  
  .grantType("password").username(username).password(passwords).build();
  
      OAuthResponse response = null;
      try {
          response = client.requestAccessToken();
      } catch (IOException e) {
          e.printStackTrace();
          //Toast.makeText(this.getContext(), e.getMessage(), 
    Toast.LENGTH_LONG).show();
  
      }
  
      String accessToken = "";
      if (response.isSuccessful()) {
          accessToken = response.getAccessToken();
         // Toast.makeText(getApplicationContext(), "acces_token" + 
   accessToken, Toast.LENGTH_LONG).show();
         new MainActivity().navigatetoHomeActivity();
          //String refreshToken = response.getRefreshToken();
      } else {
          OAuthError error = response.getOAuthError();
          String errorMsg = error.getError();
          //Toast.makeText(getApplicationContext(), errorMsg, 
    Toast.LENGTH_LONG).show();
      }
  
  
    }
  
  
    }
  </code></pre>
  
  <p>Class Home_Fragment :</p>
  
  <pre><code>package com.cuveri.mobile.controleur;
  
   import android.os.Bundle;
   import android.support.annotation.Nullable;
   import android.support.v4.app.Fragment;
   import android.view.LayoutInflater;
   import android.view.View;
   import android.view.ViewGroup;
  
   import com.example.symameri.mhis.R;
  
   public class HomeFragment extends Fragment{
  @Override
  public void onCreate(@Nullable Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
  
  }
  
  @Nullable
  @Override
  public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup 
  container, Bundle savedInstanceState) {
      return inflater.inflate(R.layout.home_fragment, container, false);
  }
  }
  </code></pre>