首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >Android测验应用程序

Android测验应用程序
EN

Stack Overflow用户
提问于 2014-09-03 14:31:32
回答 1查看 430关注 0票数 0

我是编程新手,我正在用Android创建一个简单的测验应用程序。我的问题是,我想创建不同类别的问题。我用过sqlite数据库。我已经成功地创建了“一般问题”类别,代码如下:

代码语言:javascript
运行
复制
List<Question> question_list;
int score = 0; 
int qid = 0;
Question currentQ;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    QuizHelper qh = new QuizHelper(this);
    question_list=qh.getAllQuestions();
    currentQ = question_list.get(qid);
    tv_question = (TextView)findViewById(R.id.tv_question);
    rda = (RadioButton)findViewById(R.id.radio1);
    rdb = (RadioButton)findViewById(R.id.radio2);
    rdc = (RadioButton)findViewById(R.id.radio3);
    rdd = (RadioButton)findViewById(R.id.radio4);
    rde = (RadioButton)findViewById(R.id.radio5);
    btn_next = (Button)findViewById(R.id.button1);
    setQuestionView();
    rg = (RadioGroup)findViewById(R.id.RadioGroup1);
    btn_next.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) 
        {
                answerCheck();

        }
    });
}

   public void answerCheck(){
     rda.setChecked(false);
        rdb.setChecked(false);
        rdc.setChecked(false);
        rdd.setChecked(false);
        rde.setChecked(false);

        rda.setClickable(true);
        rdb.setClickable(true);
        rdc.setClickable(true);
        rdd.setClickable(true);
        rde.setClickable(true);

        rg = (RadioGroup)findViewById(R.id.RadioGroup1);
        answer = (RadioButton)findViewById(rg.getCheckedRadioButtonId());

        if(answer != null){
            if(currentQ.getANSWER().equals(answer.getText()))
            {
                score++;
                Log.d("myscore", "" + score );
            }

        }

    if(qid < 5){
    currentQ = question_list.get(qid);
    setQuestionView();
    }       
}

public void setQuestionView(){
    counter.start();
    tv_question.setText(currentQ.getQUESTION());
    rda.setText(currentQ.getOPTA());
    rdb.setText(currentQ.getOPTB());
    rdc.setText(currentQ.getOPTC());
    rdd.setText(currentQ.getOPTD());
    rde.setText(currentQ.getOPTE());
    qid++;
}

现在我的问题是,如果我想实现另一个类别,我是否应该使用其他活动并从MainActivity继承类?数据库包含第一类的五个问题和第二类的其他五个问题。我已经使用了继承,但应用程序crashes..Can有人能帮我实现继承吗?

提前感谢

EN

回答 1

Stack Overflow用户

发布于 2014-09-03 16:03:34

不,您应该只使用一个活动。你可以制作一个通用的问题布局,并根据你的类别将其放大多次。现在只需像"getQuestionByCategory(categoryId)“一样进行查询并在你的应用中使用即可。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/25637674

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档