• Android 答题App


    答题APP,之前有个简单的单选题答题需求,我这里简单阐述下思路,完整的demo可以下载查看。
    https://download.csdn.net/download/always_and_forever_/86408940

    有定制开发需求可以发邮件到:wangzhengcheng.myself@outlook.com

    在这里插入图片描述

    1.数据源

    问题大类包含若干问题,问题下面包含多个选项,用rightTag标记出正确答案

    [
      {
        "id": 1,
        "name": "Asia", //题目名称
        "questionList": [ //问题列表
          {
            "title": "What’s the FULL name of China?", //题目描述
            "rightTag": "B", //正确答案
            "optionList": [ //选项列表
              {
                "tag": "A", //选项
                "value": "he United Kingdom of China" //选项描述
              },
              {
                "tag": "B",
                "value": "The People’s Republic of China"
              },
              {
                "tag": "C",
                "value": "The United Province of China"
              },
              {
                "tag": "D",
                "value": "The Freedom of China"
              }
          	]
    			}
          ...
          更多问题
        ]
    	}
      ...
      更多类别
    ]
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34

    2.界面设计

    用一个Activity加载,每答完一题就刷新一下页面,将下一题的内容显示出来

    题目描述
    <TextView>
    
    单选组
    <RadioGroup>
    	选项
    	<RadioButton>
    	...
    RadioGroup>
    
    下一题/完成
    <Button>
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13

    3.监听事件

    监听RadioGroup的OnCheckedChangeListener事件

    private RadioGroup.OnCheckedChangeListener onCheckedChangeListener = new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup group, int checkedId) {
                switch (checkedId) {
                    case R.id.rBtnA:
                        answer("A");
                        break;
                  	...
                }
            }
        };
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11

    4.记录分数

    选择选项之后,与正确答案做比较,答对加分

    if (currentQuestion.getRightTag().equals(answer)) {
        score.setScore(score.getScore() + 1);
        score.save();
    }
    
    • 1
    • 2
    • 3
    • 4

    currentQuestion:当前问题Object

    answer: A、B、C、D

    score:一个bean类,用来记录分数,该类继承自LitePalSupport,因此也是一张数据库表,同时拥有数据库增删改查功能(注意:这是Litepal框架的功能)

    其中userId是用户表中的id,demo也有登录和注册功能,也是通过数据库实现

    questionId是问题id,记录每个问题的作答情况

    public class Score extends LitePalSupport implements Comparable<Score> {
        private int id;//主键
        private int questionId;
        private int userId;
        private String name;
        private int score;
    
        public int getId() {
            return id;
        }
    
        public void setId(int id) {
            this.id = id;
        }
    
        public int getQuestionId() {
            return questionId;
        }
    
        public void setQuestionId(int questionId) {
            this.questionId = questionId;
        }
    
        public int getUserId() {
            return userId;
        }
    
        public void setUserId(int userId) {
            this.userId = userId;
        }
    
        public String getName() {
            return name;
        }
    
        public void setName(String name) {
            this.name = name;
        }
    
        public int getScore() {
            return score;
        }
    
        public void setScore(int score) {
            this.score = score;
        }
    
        @Override
        public int compareTo(Score o) {
            return  o.getScore() - this.score;
        }
    
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53

    实现Comparable接口,用于再答完所有题目之后,比较自己的分数排名

    5.其他-Adapter Filterable用法示例

    demo中还有个模块通过retrofit网络请求,将请求到的集合显示到recyclerview当中,在recyclerview的adapter中,实现Filterable接口,重写getFilter方法,根据传入的字符串进行过滤筛选,同时实现自定义的排序,例如首字母A-Z排序或者Z-A排序等。这部分代码主要在CountryAdapter.java里面

  • 相关阅读:
    处理不平衡数据的十大 Python 库
    0049【Edabit ★☆☆☆☆☆】【修改Bug代码】Buggy Code
    中国剩余定理
    Mac搭建anaconda环境并安装深度学习库
    FPGA刷题——序列检测
    OJ:循环队列
    矩阵相乘详解
    徐建鸿:深耕中医康养的“托钵行者”
    calc方法和vue中calc不生效踩坑
    8.6 SignalR服务器端消息推送
  • 原文地址:https://blog.csdn.net/always_and_forever_/article/details/126467733