Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Roman Nurik's Wizard pager - how to access collected data?

I am trying to make a wizard using Roman Nurik's library (https://plus.google.com/113735310430199015092/posts/6cVymZvn3f4).

I am having trouble accessing the collected data from the Review Fragment. I made mCurrentReviewItems public in ReviewFragment and then I tried it like this

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.

like image 404
urSus Avatar asked Feb 08 '13 04:02

urSus


2 Answers

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

For single page variable:

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

For customized page:

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

If you want to assign the 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 from the example, change whatever suit you. Never try the multi one, I think it is more or less the same.

like image 90
Allen Chan Avatar answered Sep 22 '22 10:09

Allen Chan


Sorry for big delay, but I think that someone will found this info useful. I found a way to get all ReviewItems since you can have a lot of branches and you won't be able to use the first answer.

I'm pretty sure, that your mPagerAdapter::getItem code looked like in example (so it just returned new fragment, instead of returning current pager fragment). You have to use instantiateItem to get reference on 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());
  }
}
like image 3
Anton Shkurenko Avatar answered Sep 20 '22 10:09

Anton Shkurenko