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

前端 未结 5 1161
既然无缘
既然无缘 2021-02-09 06:56

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

相关标签:
5条回答
  • 2021-02-09 07:07

    The best solution is to include this library in your project as module, and implement your own method for getting review items in ReviewFragment.

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

    I am not sure why developer did not add that. It's the most important thing in project. Choose items and DO something with them.

    0 讨论(0)
  • 2021-02-09 07:09

    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.

    0 讨论(0)
  • 2021-02-09 07:12

    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());
      }
    }
    
    0 讨论(0)
  • 2021-02-09 07:20

    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 讨论(0)
  • 2021-02-09 07:27

    Anyone still looking for a solution for this issue you can use following code

        ArrayList<ReviewItem> reviewItems = new ArrayList<ReviewItem>();
        for (Page page : mWizardModel.getCurrentPageSequence()) {
            page.getReviewItems(reviewItems);
        }
    
    0 讨论(0)
提交回复
热议问题