0

Initially when the fragment is loaded it has layout:

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
        Bundle savedInstanceState) {
    View view = null;
    view = inflater.inflate(R.layout.authenticate, null);
    return view;
}

Later in the fragment I'm perfomring a functionality which will call startActivityForResult(intent, 1);

If the reponse is successful, I want to replace the layout of the fragment with another layout, say: R.layout.success

In onActivityResult() what should I write.

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    // Some code
    if(success){
        // WHAT TO CODE HERE TO REPLACE THE LAYOUT R.layout.authenticate TO R.layout.success
    }

}
reiley
  • 3,759
  • 12
  • 58
  • 114

1 Answers1

0

You can pass an index while calling the Fragment from the Activity in a Bundle as

Bundle bundle=new Bundle();
bundle.putInt("index", 0);//pass 0 for the first time and pass 1 from onActivityResult
MyFragment frag=new MyFragment();
frag.setArguments(bundle);

And in Fragment get the index and load the layout accordingly

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
     int index=getArguments().getInt("index");
     View view = null;
     if(index == 0) {
        view = inflater.inflate(R.layout.authenticate, null);
     } else {
        //another layout to load
     }
     return view;
}
bakriOnFire
  • 2,685
  • 1
  • 15
  • 27
  • `onCreateView()` is not getting called when the child activity is finihed. Flow is starting from `onResume()` – reiley Oct 21 '13 at 11:26