[英]How to load themed activity after correct or wrong answer in a quiz?
OK, I was adviced to make a new thread for my question. 好的,我被建议为我的问题创建一个新主题。 I am using imported SQLite database.
我正在使用导入的SQLite数据库。 Anyway, I have made two themed dialogs for right and wrong answers, and I want to show them when right or wrong answer is clicked.
无论如何,我为正确和错误答案创建了两个主题对话框,当单击正确或错误答案时,我想显示它们。 Here's the code in my activity, cut out parts:
这是我活动中的代码,删节了:
private class Answer {
public Answer(String opt, boolean correct) {
option = opt;
isCorrect = correct;
}
String option;
boolean isCorrect;
}
final OnClickListener clickListener = new OnClickListener() {
public void onClick(View v) {
Answer ans = (Answer) v.getTag();
if (ans.isCorrect) {
Toast toastT = Toast.makeText(Kviz.this, "Correct!", Toast.LENGTH_SHORT);
toastT.show();
finish();
}else{
Toast toastP = Toast.makeText(Kviz.this, "Wrong!", Toast.LENGTH_SHORT);
toastP.show();
}
startActivity(getIntent());
}
};
When I use Toast like above it works fine, but when I try to use my themed activity like this, it doesn't, instead it goes right to next question, and when I press back button on my phone I get that themed popup activity: 当我像上面那样使用Toast时,它工作正常,但是当我尝试使用这样的主题活动时,它却没有,而是转到下一个问题,当我按手机上的“后退”按钮时,我得到了主题弹出式活动:
final OnClickListener clickListener = new OnClickListener() {
public void onClick(View v) {
Answer ans = (Answer) v.getTag();
if (ans.isCorrect) {
Intent t = new Intent("rs.androidaplikacijekvizopstekulture.TACANODGOVOR");
startActivity(t);
finish();
}else{
Intent p = new Intent("rs.androidaplikacijekvizopstekulture.POGRESANODGOVOR");
startActivity(p);
}
startActivity(getIntent());
}
};
To repeat, I get the themed activity when I press the back button, I get the wrong ones and the correct ones, as I go backwards. 重复一遍,当我按下后退按钮时,我得到了主题活动,当我向后走时,我得到了错误的活动和正确的活动。 I just want to show that dialog and then to load the next question, like it does with the Toast.
我只想显示该对话框,然后加载下一个问题,就像Toast一样。 Just to mention that this activity loading works fine in my other acitivity, only it goes after simple button click, no question and answers.
只需提一下,此活动加载在我的其他活动中都可以正常工作,只有在单击了简单按钮之后,才可以进行问答。
The reason is after calling any of (right/wrong) startActivity
, it moves on to call startActivity(getIntent());
原因是在调用了(正确/错误)
startActivity
任何一个之后,它继续调用startActivity(getIntent());
method. 方法。 One way is to make your TACANODGOVOR & POGRESANODGOVOR Dialog activity by adding following tag/value for these activities in manifest file
android:theme="@android:style/Theme.Dialog"
eg 一种方法是通过在清单文件
android:theme="@android:style/Theme.Dialog"
为这些活动添加以下标记/值,以使TACANODGOVOR和POGRESANODGOVOR对话框活动
<activity ... android:theme="@android:style/Theme.Dialog" />
It will display TACANODGOVOR & POGRESANODGOVOR as dialog and unless user presses back button (or any exit button activities may have), it wont proceed to next line. 它将显示TACANODGOVOR和POGRESANODGOVOR作为对话框,除非用户按下后退按钮(或任何退出按钮活动可能具有),否则它将不会进入下一行。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.