如何在测验正确或错误的答案后装入主题活动? [英] How to load themed activity after correct or wrong answer in a quiz?

查看:183
本文介绍了如何在测验正确或错误的答案后装入主题活动?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

OK,我劝作出新的线程我的问题。我公司采用进口的SQLite数据库。无论如何,我已经为正确和错误的回答了两个主题的对话,我想向他们展示点击正确或错误的答案时。下面是我的活动code,切出部分:

OK, I was adviced to make a new thread for my question. I am using imported SQLite database. 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());
            }
    };

当我使用吐司像上面它工作正常,但是当我尝试使用我的主题活动就是这样,不是这样,而是去正确的下一个问题,当我preSS背扣我的手机上我得到的主题活动弹出:

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:

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());
            }
    };

要再说一遍,我得到的主题活动时,我preSS后退按钮,我得到的那些错误的和正确的人,因为我去倒退。我只是想显示对话框,然后加载下一个问题,如它与面包一样。仅举这一活动装载作品在我的其他活性的研究得很好,只有它会简单的按钮点击后,毫无疑问和解答。

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. Just to mention that this activity loading works fine in my other acitivity, only it goes after simple button click, no question and answers.

推荐答案

原因是调用任何(对/错) startActivity ,它移动调用后 startActivity(getIntent()); 方法。一种方法是使你的TACANODGOVOR&放大器;通过在清单文件,这些活动将以下标记/值POGRESANODGOVOR对话活动安卓主题=@安卓风格/ Theme.Dialog例如

The reason is after calling any of (right/wrong) startActivity, it moves on to call 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" e.g.

<activity ... android:theme="@android:style/Theme.Dialog" />

它会显示TACANODGOVOR&安培; POGRESANODGOVOR为对话框,除非用户presses后退按钮(或退出按钮活动可能),它不会继续执行下一行。

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.

这篇关于如何在测验正确或错误的答案后装入主题活动?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆