0

I'm trying to use Roman Nurik's WizardPager library to add and edit a custom object but I'm having troubles to assign data to certain pages (I guess I'll struggle to access the data once ready to save it as well). I don't get the concept of findByKey() and cannot assign data to pages located "underneath" a BranchPage.

Example:

My wizard model looks like this:

protected PageList onNewRootPageList() { 
    return new PageList(
       new CustomerInfoPage(this, "Page 1"),
       new BranchPage(this, "Branch page")
          .addBranch("Alternative 1", new SingleFixedChoicePage(this, "Page 2.1"))
          .addBranch("Alternative 2", new CustomerInfoPage(this, "Page 2.2"))
    );        
}

Assigning data to the first page works fine using the code below in MainActivity.java. (Thanks to Allen Chan's answer here).

    public void onCreate(Bundle savedInstanceState) {
       super.onCreate(savedInstanceState);
       setContentView(R.layout.wizard_main);

       ...

       Bundle data = new Bundle();
       if (!TextUtils.isEmpty(CustomerInfoPage.MY_DATA_KEY)) {
          data.putString(CustomerInfoPage.MY_DATA_KEY, person.getName());
          mWizardModel.findByKey("Page 1").resetData(data);
    }

But how to assign data to the second CustomerInfoPage acting as a sub-page to the BranchPage? I've tried all sort of keys like

mWizardModel.findByKey("Branch page:Page 2.2").resetData(data);

but without luck. Everything I've tried causes NullPointerException on that particular row.

Please advice - thanks in advance!

Community
  • 1
  • 1

1 Answers1

1

1st Question) Retrieve data from branch

In EmployerWizardPager when mNextButton has been clicked

if (mPager.getCurrentItem() == mCurrentPageSequence.size()){

//your example
mWizardModel.findByKey("Alternative 1:Page 2.1").getData().getString(Page.SIMPLE_DATA_KEY);
mWizardModel.findByKey("Alternative 2:Page 2.2").getData().getString(Page.SIMPLE_DATA_KEY);

}

2nd Question) Load data into WizardPager

I am not sure if this is the best way to do it, but this is how I accomplished loading data into the wizard. I saved my values in an external database (you can also save in SQLite or Shared Preferences).

Some of my sample code from WizardFragment for clarification:

new SingleFixedChoicePage(this, "HoursPerWeek")
                    .setChoices("15", "20", "25", "30", "35", "40", "50", "60")
                    .setRequired(true),

Titles (also key): "Type of search", "HoursPerWeek", "Address", "Hourly:Hourly Wage" (this is a branch)

Keys: "_" is my Page.SIMPLE_DATA_KEY (for all values except InfoPages) "address" is my key for CompanyInfoPage

Answers that are loaded into Wizard: "Quick" ,"60", "14 Oak Wood Rd Brighton MA" , "$68.00"

//MY CODE in onCreate in EmployerWizardPager

        Bundle bundle = new Bundle();



        Bundle bdl1 = new Bundle();
        bdl1.putString("_","Quick");
        bundle.putBundle("Type of search",bdl1);


        Bundle bdl2 = new Bundle();
        bdl2.putString("_","60");
        bundle.putBundle("HoursPerWeek",bdl2);



        Bundle bdl3 = new Bundle();
        bdl3.putString("address","14 Oak Wood Rd Brighton MA");
        bundle.putBundle("Address",bdl3);


        Bundle bdl4 = new Bundle();
        bdl4.putString("_","$68.00");
        bundle.putBundle("Hourly:Hourly Wage",bdl4);




        mWizardModel.load(bundle);

Good Luck!

eddiep
  • 96
  • 2
  • 8