Using the Roman Nurik Wizard pager example, how can I access data from previous pages in later pages?

Excuse my lack of experience, I am a slow programming language.

I have embedded the Roman Nurik Wizard Pager model in my app to get the user's phone model and headphone type. Then I want to query the database using these two results on the third page ...

I have a database query method (which is inside my WizardModel class (SandwichWizardModel in the example)) that, for now, returns every record to my database and puts it in a list to select. I want to be able to adapt this method to take rows from pages 1 and 2 to query the database and find matches on page 3.

I was given the following advice:

mWizardModel.findByKey("TITLE_OF_YOUR_PAGE").getData().getString(YourPage.YOUR_FIELD_DATA_KEY)

      

Which in my code assigns:

mWizardModel.findByKey("Phone Model").getData().getString(SingleTextFieldPage.SIMPLE_DATA_KEY);

      

But I can't figure out how to get the mWizardModel instance. I have tried various methods, but I am getting a null object exception. Feeling like it might be due to context in a class with no activity, I also tried a new activity using:

public class Test extends Activity {

HearingTestWizardModel mWizardModel = new HearingTestWizardModel(getApplicationContext());
String testOut;

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

    testOut = mWizardModel.findByKey("Phone Model").getData().getString(SingleTextFieldPage.SIMPLE_DATA_KEY);


    Log.i("The results from before are: ", testOut);
}

      

}

But I had no luck with that. How do I create an instance of mWizardModel so that I can call data from it?

If I need to provide more information, please ask. The sample code used is here: https://github.com/romannurik/Android-WizardPager

+3


source to share


1 answer


The WizardPager is not built for what you want. You will need to direct your login to page 3.. You can do this using SharedPreferences. Be careful that the WizardPager always loads the next page before showing it. Therefore, you need to figure out when your 3. page is actually visible to the user.

You can do it with this code inside your snippet:



@Override
public void setUserVisibleHint(boolean isVisibleToUser) {
    super.setUserVisibleHint(isVisibleToUser);
    if (isVisibleToUser) {
        if (getView() != null) {
            // load data from page 1&2
            refreshView(getView());
        }
    }
}

      

+1


source







All Articles