简体   繁体   English

在测验中正确或错误回答后如何加载主题活动?

[英]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.

相关问题 Java乘法测验,如果答案错误,如何循环 - Java multiplication quiz, how to loop if the answer is wrong 测验应用程序,更改错误的按钮颜色并针对错误的答案选择纠正答案,Android - Quiz app, change button color of wrong and correct answer on wrong answer selection, android 用户在Java中的测验程序中选择了错误答案后如何重复问题 - How to repeat the question after the user chose the wrong answer on my quiz program in java 这是一个测验程序,我必须从 4 个选项中选择 1 个选项,然后我必须显示用户得到的错误和正确答案的数量 - this is a quiz program where i have to select 1 option from 4 and after I have to display how many wrong and right answer a user get 如何在其他活动中发送正确答案和所选答案? - How can i send the correct answer and the chosen answer in another activity? 错误识别Java测验程序中的正确答案 - Error Recognizing Correct Answer in a Java Quiz Program 答案正确时不正确 Android 测验应用程序 - Incorrect when the answer is correct Android Quiz app 如何根据测验应用程序的管理操作向最终用户加载一组问题和答案 - How to load set of question and answer to end user based on the admin action for quiz application 错误答案后重复 - Repeating after wrong answer Android quiz 如何根据答案显示问题? - Android quiz How to show the question based on the answer?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM