Open femosso opened 9 years ago
@femosso Late response, but in case you need it. I made a workaround, but this is not the best solution. Also, it is not dynamic in the sense of adding pages at any time.
I downloaded all the code and inserted it into my app's code. Then I had to resolve all issues (copy resources, etc.)
Then, I modified AbstractWizardModel
the following way:
public AbstractWizardModel(Context context) {
mContext = context;
}
public void startRootPageList() {
mRootPageList = onNewRootPageList();
}
Then, my wizard model constructor:
public WizardModel(Context context, Content content) {
super(context);
this.content = content;
super.startRootPageList();
}
Finally, onNewRootPageList
callback:
@Override
protected PageList onNewRootPageList() {
if (content != null) {
PageList pageList = new PageList();
// Add pages to pageList according to content
return pageList;
}
return new PageList();
}
Old post, still this answer can help someone. I got it resolved by moving the AbstractWizzardModel instantiation to the onCreate method on the Activity. Like below:
public class WizardActivity extends FragmentActivity implements
PageFragmentCallbacks,
ReviewFragment.Callbacks,
ModelCallbacks {
private AbstractWizardModel mWizardModel;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mWizardModel = new ActivityWizardModel(this);
}
}
With that change you can do:
mContext.getString(R.string.your_string)
in any place at you concrete model.
I hope that helps.
PS: you can't load resource at that time because the method onCreate()
do an eternal loop when you try to get the application context.
In the sample code the AbstractWizardModel is being statically instantiated when MainActivity is created. Once this is done, the onNewRootPageList() callback is immediately triggered in the wizard model and I couldn't find a way to load the PageList with some dynamic contents.
The workaround I found for this is to make AbstractWizardModel class a inner class in MainActivity and have my dynamic content a global variable so I could access it from AbstractWizardModel. This generates a side effect since I'm no longer instantiating AbstractWizardModel class when the MainActivity is create. I'm instantiating it o onCreate() callback, so it is being called some time later in comparison with original code.
Is there an alternative way to load content in the form (PageList) dynamically?