[英]How do I put data from Roman Nuriks Wizard Pager review into database?
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. 我需要做的只是从向导末尾的评论页面获取所有数据并将其放入我的SQLite数据库中,以便将来在我的应用程序中使用它。
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 这是我到目前为止所尝试的内容,但总是返回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);
}
}
}
});
@Derek Smith I have figured out a way to save the data and it works for me. @Derek Smith我找到了一种保存数据的方法,它对我有用。
This is my AbstractWizardModel class block: 这是我的AbstractWizardModel类块:
@Override
protected PageList onNewRootPageList() {
return new PageList(
new LoginInfoPage(this, "Login Information").setRequired(true));
}
It is similar to the sample provided with Library. 它类似于随Library提供的示例。
Now in your MainActivity, write as below: 现在在MainActivity中,写如下:
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, 问候,
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 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();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.