Roman Nurik Wizard pager - how to access collected data?

I am trying to create wizards using the Roman Nurik library ( https://plus.google.com/113735310430199015092/posts/6cVymZvn3f4 ).

I'm having trouble accessing the collected data from a review fragment. I made mCurrentReviewItems public in ReviewFragment, and then I tried this as

mNextButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { if (mPager.getCurrentItem() == mCurrentPageSequence.size()) { ReviewFragment reviewFragment = (ReviewFragment) mPagerAdapter.getItem(mPager.getCurrentItem()); for (ReviewItem item : reviewFragment.mCurrentReviewItems) Log.d(MainActivity.TAG, "Item: " + item.getDisplayValue()); } } else { if (mEditingAfterReview) { mPager.setCurrentItem(mPagerAdapter.getCount() - 1); } else { mPager.setCurrentItem(mPager.getCurrentItem() + 1); } } } }); 

However its always null.

+7
source share
4 answers

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

For one page variable:

 String data = mWizardModel.findByKey("Sandwich:Bread").getData().getString(Page.SIMPLE_DATA_KEY); 

For a personalized page:

 String data = mWizardModel.findByKey(THE_KEY).getData().getString(CustomerInfoPage.YOUR_DATA_KEY); 

If you want to assign data back to the wizard, put this at the end of onCreate in FragmentActivity:

 Bundle data = new Bundle(); if (!TextUtils.isEmpty(DATA_STRING)) { data.putString(Page.SIMPLE_DATA_KEY, DATA_STRING); mWizardModel.findByKey("Sandwich:Bread"").resetData(data); } 

The key "Sandwich: Bread" is shown in the example, change any option that suits you. Never try multi, I think it is more or less the same.

+11
source

Sorry for the big delay, but I think someone will find this information useful. I found a way to get all the ReviewItems , since you can have many branches and you cannot use the first answer.

I'm sure your mPagerAdapter::getItem code looked like an example (so it just returned a new fragment instead of returning the current pager fragment). You must use instantiateItem to get a link to your ReviewFragment .

 Object o = mPager.getAdapter().instantiateItem(mPager, mPager.getCurrentItem()); if(o instanceof ReviewFragment) { List<ReviewItem> items = ((ReviewFragment) o).getCurrentReviewItems(); if(items != null) { Log.v(TAG, "Items are: " + items.toString()); } } 
+3
source

This is my code @Anton_Shkurenko

 mNextButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { if (mPager.getCurrentItem() == mCurrentPageSequence.size()) { Object o = mPager.getAdapter().instantiateItem(mPager, mPager.getCurrentItem()); if(o instanceof ReviewFragment) { List<ReviewItem> items = ((ReviewFragment) o).getCurrentReviewItems(); if(items != null) { Log.v(TAG, "Items are: " + items.toString()); } } } } }); 
0
source

The best solution is to include this library in your project as a module and implement your own method to get the review elements in ReviewFragment.

 public List<ReviewItem> getReviewItems() { return mCurrentReviewItems; } 

I am not sure why the developer did not add this. This is the most important thing in the project. Select items and do something with them.

0
source

All Articles