title: change fragment layout programmatically
body: <p>I have two tabs, which are fragments, and one is for login (login fragment). After it clicks login, a new activity (login activity) will pop up, and then the user needs to login. If he has successfully logged in, the login activity will be closed by using <code>finish()</code>. And then I want to change the layout of the tab from login fragment to welcome fragment, using <code>onActivityResult()</code>. </p>
  
  <p>I have two layouts created, login fragment layout and welcome fragment layout. However, I do not know how to change the layout since <code>setContentView()</code> cannot be used.</p>
  
  <pre><code>public class UserLoginTab extends Fragment {
  
  String username = "";
  
  Button loginButton;
  
  @Override
  public View onCreateView(LayoutInflater inflater, ViewGroup container,
                           Bundle savedInstanceState) {
      View rootView = inflater.inflate(R.layout.user_login_tab, container, false);
  
      loginButton = (Button) rootView.findViewById(R.id.btn_login);
      loginButton.setOnClickListener(new View.OnClickListener() {
  
          @Override
          public void onClick(View v) {
              Intent intent = new Intent(getActivity(), LoginActivity.class);
              startActivityForResult(intent, 1);
          }
      });
  
  
      return rootView;
  }
  
  public void onActivityResult(int requestCode, int resultCode, Intent data) {
      super.onActivityResult(requestCode, resultCode, data);
      if (requestCode == 1) {
          if(resultCode == RESULT_OK){
              username=data.getStringExtra("username");
              //change layout here and add the username to a textView
              //The layout is (R.layout.welcome_tab)
          }
      }
  }
  
  
  }
  </code></pre>