How do I put data from Roman Nuriks Wizard Pager r

2019-02-28 08:42发布

问题:

Alright so I know this has been asked before but the question and answer both didn't help me in my situation. What I need to do is simply get all of the data from the review page at the end of the wizard and put it into my SQLite database so that I may use it in the future within my application.

I'm not even sure which class I should be working on in this case. I really hope someone who's had trouble with this before can help me because I've been searching for days and I'm stumped!

Thanks in advance for any help you can give me!

here is my what I've tried so far however it is always returning null

  mNextButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {



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

                String title = mWizardModel.findByKey("Surf:Post Title").getData().getString(SingleTextFieldPage.SIMPLE_DATA_KEY);
                int price = mWizardModel.findByKey("Surf:Price").getData().getInt(NumberPage.SIMPLE_DATA_KEY);  
                String maincat = mWizardModel.findByKey("Main Category").getData().getString(Page.SIMPLE_DATA_KEY);

                Long newId = myDb.insertRow(title, price, maincat);

                DialogFragment dg = new DialogFragment() {
                    @Override
                    public Dialog onCreateDialog(Bundle savedInstanceState) {
                        return new AlertDialog.Builder(getActivity())
                                .setMessage(R.string.submit_confirm_message)
                                .setPositiveButton(R.string.submit_confirm_button, null)
                                .setNegativeButton(android.R.string.cancel, null)
                                .create();
                    }
                };
                dg.show(getSupportFragmentManager(), "place_order_dialog");
            } else {
                if (mEditingAfterReview) {
                    mPager.setCurrentItem(mPagerAdapter.getCount() - 1);
                } else {
                    mPager.setCurrentItem(mPager.getCurrentItem() + 1);
                }
            }

        }
    });

回答1:

@Derek Smith I have figured out a way to save the data and it works for me.

This is my AbstractWizardModel class block:

@Override
protected PageList onNewRootPageList() {

    return new PageList(
            new LoginInfoPage(this, "Login Information").setRequired(true));
}

It is similar to the sample provided with Library.

Now in your MainActivity, write as below:

String data = mWizardModel.findByKey("LoginInformation").getData().getString(LoginInfoPage.EMAIL_DATA_KEY);

The main thing to retrieve data is "key". In my case, key is "Login Information" which is also your title.

Hope it helps.

Regards,



回答2:

I think this is what you need:

This is hierarchy of quiz data entered:

Page List > Branch Page > Branch(Question) > Choice(Single or Multiple)

String data = mWizardModel.findByKey("Question:Choice").getData().getString(Page.SIMPLE_DATA_KEY);

Example:

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

Also this is what i did to get all selected answers from Question and also to calculate score,

Inside

mNextButton.setOnClickListener

if (mPager.getCurrentItem() == mCurrentPageSequence.size()) {
                    int score = 0;
                    String q1 = mWizardModel.findByKey("Yes:Question 1")
                            .getData().getString(Page.SIMPLE_DATA_KEY);
                    String q2 = mWizardModel.findByKey("Yes:Question 2")
                            .getData().getString(Page.SIMPLE_DATA_KEY);
                    String q3 = mWizardModel.findByKey("Yes:Question 3")
                            .getData().getString(Page.SIMPLE_DATA_KEY);
                    String q4 = mWizardModel.findByKey("Yes:Question 4")
                            .getData().getString(Page.SIMPLE_DATA_KEY);
                    String q5 = mWizardModel.findByKey("Yes:Question 5")
                            .getData().getString(Page.SIMPLE_DATA_KEY);
                    String q6 = mWizardModel.findByKey("Yes:Question 6")
                            .getData().getString(Page.SIMPLE_DATA_KEY);
                    String q7 = mWizardModel.findByKey("Yes:Question 7")
                            .getData().getString(Page.SIMPLE_DATA_KEY);
                    String q8 = mWizardModel.findByKey("Yes:Question 8")
                            .getData().getString(Page.SIMPLE_DATA_KEY);
                    String q9 = mWizardModel.findByKey("Yes:Question 9")
                            .getData().getString(Page.SIMPLE_DATA_KEY);
                    String q10 = mWizardModel.findByKey("Yes:Question 10")
                            .getData().getString(Page.SIMPLE_DATA_KEY);

                    if (q1 == "c3") {
                        score = score + 1;
                    }
                    if (q2 == "c2") {
                        score = score + 1;
                    }
                    if (q3 == "c1") {
                        score = score + 1;
                    }
                    if (q4 == "c4") {
                        score = score + 1;
                    }
                    if (q5 == "c1") {
                        score = score + 1;
                    }
                    if (q6 == "c4") {
                        score = score + 1;
                    }
                    if (q7 == "c2") {
                        score = score + 1;
                    }
                    if (q8 == "c3") {
                        score = score + 1;
                    }
                    if (q9 == "c1") {
                        score = score + 1;
                    }
                    if (q10 == "c4") {
                        score = score + 1;
                    }
                    Toast.makeText(getApplicationContext(), "Score:" + score,
                            Toast.LENGTH_LONG).show();