1

I can have the following fragments in a dynamic multi-step sign up form inside the view pager:

User wants to sign up as a Company:
     Page 0              Page  1            Page  2          Page 3
ChooseUserFragment | AddressFragment  | CompanyFragment | DataFragment |

User wants to sign up as a Client:
      Page 0              Page  1           Page  2
ChooseUserFragment | AddressFragment  | DataFragment |

I destroy all the fragments and recreate them when the user change the user type option (Company -> Client or vice versa), and click to proceed to the form, but i do not want to make the user type everything again if he changes from one type to another, so I save the information typed by him in a bundle on the onSaveInstanceState method and recover it onViewStateRestored

The problem is that the bundle being passed to the DataFragment when I recreate the fragments comes from CompanyFragment not the DataFragment one. Is it possible to make the bundle comes from the correct fragment even changing the position of them?

Code being used to recreate the Fragments:

 @Override
  public int getCount() {
    if(isCreatingClientUser){
      return 3;
    } else{
      return 4;
    }
  }
@Override
  public SignUpFragment getItem(int position) {
    if(position == 0){ // Welcome screen
      return new SignUpWelcomeFragment();
    }else if(position == 1){ // Address screen
      return new SignUpAddressFragment();
    }else if(position == 2){ // Company screen or User Data
      if(isCreatingClientUser){
        return new SignUpDataFragment();
      } else{
        return new SignUpCompanyFragment();
      }
    }else if(position == 3){ // User Data screen
      return new SignUpDataFragment();
    }else{
      return null;
    }
  }

  //This is called when notifyDataSetChanged() is called
  @Override
  public int getItemPosition(Object object) {
    // refresh all fragments when data set changed
    return PagerAdapter.POSITION_NONE;
  }

enter image description here

Roni Castro
  • 1,968
  • 21
  • 40

0 Answers0