本文为大家分享了Android APP编写的简单答题器,此答题器可以通过Next按钮选择下一题,新写题目的类Question,有两个成员变量。

java代码:

package com.android.testrecord;

/**

* Created by wang on 16-10-19.

*/

public class Question {

private int mTextResId;

private boolean mAnswerTrue;

public Question(int textResId, boolean answerTrue) {

mTextResId = textResId;

mAnswerTrue = answerTrue;

}

public int getTextResId() {

return mTextResId;

}

public boolean isAnswerTrue() {

return mAnswerTrue;

}

public void setTextResId(int textResId) {

mTextResId = textResId;

}

public void setAnswerTrue(boolean answerTrue) {

mAnswerTrue = answerTrue;

}

}

java代码:

package com.android.testrecord;

import android.support.v7.app.AppCompatActivity;

import android.os.Bundle;

import android.view.View;

import android.widget.Button;

import android.widget.TextView;

import android.widget.Toast;

public class QuizActivity extends AppCompatActivity {

private Button mTrueButton;

private Button mFalseButton;

private Button mNextButton;

private TextView mQuestionTextView;

private Question[] mQuestionBank = new Question[] {

new Question(R.string.question_oceans, true),

new Question(R.string.question_mideast, false),

new Question(R.string.question_africa, false),

new Question(R.string.question_americas,true),

new Question(R.string.question_asia, true),

};

private int mCurrentIndex = 0;

private void updateQuestion() {

int question = mQuestionBank[mCurrentIndex].getTextResId();

mQuestionTextView.setText(question);

}

private void checkAnswer(boolean userProessedTrue) {

boolean answerIsTrue = mQuestionBank[mCurrentIndex].isAnswerTrue();

int messageId = 0;

if (userProessedTrue == answerIsTrue)

messageId = R.string.correct_toast;

else

messageId = R.string.incorrect_toast;

Toast.makeText(this, messageId, Toast.LENGTH_SHORT).show();

}

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_quiz);

mQuestionTextView = (TextView) findViewById(R.id.question_test_view);

// int question = mQuestionBank[mCurrentIndex].getTextResId();

// mQuestionTextView.setText(question);

updateQuestion();

mTrueButton = (Button) findViewById(R.id.true_button);

mTrueButton.setOnClickListener(new View.OnClickListener() {

@Override

public void onClick(View v) {

// Does nothing yet, but soon!

/* Toast.makeText(QuizActivity.this,

R.string.incorrect_toast,

Toast.LENGTH_SHORT).show(); */

checkAnswer(true);

}

});

mFalseButton = (Button) findViewById(R.id.false_button);

mFalseButton.setOnClickListener(new View.OnClickListener() {

@Override

public void onClick(View v) {

// Does nothing yet, but soon!

/* Toast.makeText(QuizActivity.this,

R.string.correct_toast,

Toast.LENGTH_SHORT).show(); */

checkAnswer(false);

}

});

mNextButton = (Button) findViewById(R.id.next_button);

mNextButton.setOnClickListener(new View.OnClickListener() {

@Override

public void onClick(View v) {

mCurrentIndex = (mCurrentIndex + 1) % mQuestionBank.length;

// int question = mQuestionBank[mCurrentIndex].getTextResId();

// mQuestionTextView.setText(question);

updateQuestion();

}

});

}

}

xml代码:

android:layout_width="match_parent"

android:layout_height="match_parent"

android:gravity="center"

android:orientation="vertical" >

android:id="@+id/question_test_view"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:padding="24dp"/>

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:orientation="horizontal">

android:id="@+id/true_button"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="@string/true_button"/>

android:id="@+id/false_button"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="@string/false_button"/>

android:id="@+id/next_button"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="@string/next_button"/>

代码:

GeoQuiz

Constantinople is the largest city in Turkey.

True

False

Correct!

Incorrect!

Settings

Next

The Pacific Ocean is larger than the Atlantic Ocean.

The Suez Canal connects the Red Sea and the Indian Ocean.

The source of the Nile River is in Egypt.

The Amazon River is the longest river in the Americas.

Lake Baikal is the world\'s oldest and deepest freshwater lake.

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持找一找教程网。

android开发答题app,Android APP编写简单答题器相关推荐

  1. 安卓开发日记(1) - 安装 Android 开发环境和 first app

    安装 Android 开发环境 安装 Android Studio 并升级到最新版本(本文使用 1.0.2 版本) 如果没有安装JDK, 安装 64-bit JDK MAC 下需要手动装一下HAXAM ...

  2. Android开发日志打卡APP(二)

    Android开发日志打卡APP(二) 文章目录 Android开发日志打卡APP(二) 前言 开发过程 一.背景和标题 二.日志图标 三.日志弹框 前言 在之前的文章中,准备工作已经完成,现在我们将 ...

  3. Android开发日志打卡APP(一)

    Android开发日志打卡APP(一) 文章目录 Android开发日志打卡APP(一) 简介 界面展示 内容总结 1.控件 2.布局 3.技术 开发过程 准备工作 启动页面 底部导航栏 简介 ​ 初 ...

  4. Android开发详解之App升级程序一点通

    Android开发详解之App升级程序一点通 结束语 UpdateManager.java import java.io.File; import java.io.FileOutputStream; ...

  5. android开发 实现动态获得app的cpu占有率并导出文件的两种方法。

    android开发 实现动态获得app的cpu占有率并导出文件的两种方法. 最近在做学校实验室的项目的时候,师兄要求我对app的性能进行评估,主要是从电量.cpu占有率.python模型的响应时间三者 ...

  6. (转)解决android开发人员,手机app图标显示不正确问题

    (转)解决android开发人员,手机app图标显示不正确问题 参考文章: (1)(转)解决android开发人员,手机app图标显示不正确问题 (2)https://www.cnblogs.com/ ...

  7. android开发分页查询,Android开发中实现分页效果的简单步骤

    分页加载在程序开发中是必备的,但是我们实现这个功能并不仅仅为了美观,用户体验也是很重要的,爱站技术频道下面就带大家了解Android开发中实现分页效果的简单步骤,感兴趣的小伙伴们参考看看吧! 具体内容 ...

  8. 全网最全Android开发工具,Android开发框架大全

    涵盖Android方方面面的技术, 目前保持更新. 时刻与Android开发流行前沿同步. 目录 一.工具 Android开发工具 在线工具宝典大全 二.框架 *缓存框架* DiskLruCache ...

  9. Android 开发工具集合 - (Android Dev Tools)

    收集整理Android开发所需的Android SDK.开发中用到的工具.Android开发教程.Android设计规范,免费的设计素材等. 欢迎大家推荐自己在Android开发过程中用的好用的工具. ...

  10. 视频教程-快速入门Android开发 视频 教程 android studio-Android

    快速入门Android开发 视频 教程 android studio 任苹蜻,爱学啊创始人 & CEO,曾就职于某二车手公司担任Android工程师后离职创办爱学啊,我们的宗旨是:人生苦短,我 ...

最新文章

  1. 简单的文本框输入实时计数
  2. python基础教程书籍推荐-入门python有什么好的书籍推荐?
  3. IDE-Android Studio -FAQ-使用习惯(不断更新 欢迎留言)
  4. JavaWeb之Servlet学习-----实现文件动态下载功能 手写servlet 手动构建web程序
  5. nestjs CRUD
  6. 4种kill某个用户所有进程的方法
  7. 机器学习决策树_机器学习与数据科学决策树指南
  8. java一个简单的管理系统
  9. 集合框架(数据结构之栈和队列)
  10. Clob,Blob,InputStream,byte 互转
  11. 高斯消去法,列主元法,LU分解法python程序
  12. 如何减小电压跟随器输出电阻_运算放大器和比较器还傻傻分不清楚?一篇图文教你轻松辨认...
  13. 在Mac和PC之间共享鼠标键盘(拥有多台电脑者必看)
  14. office2007安装失败2902_Office2007安装出错怎么办?安装出错原因及解决方法分享
  15. 三、静息状态的神经元外膜
  16. 怎样在excel表格中画斜线并打字_你会用Excel做 表头 吗?
  17. dma循环刷新oled屏幕
  18. D. Challenging Valleys
  19. 直播:京东大数据的应用!
  20. sharp s2 android 9,夏普AQUOS S2值得买吗?夏普S2全面深度评测

热门文章

  1. 【白皮书分享】2022新职业教育洞察白皮书:“职”成机遇,“育”见未来.pdf...
  2. 算法工程师面试备战笔记4_余弦相似与欧氏距离有什么区别和联系
  3. 全球首发!惯性导航导论(剑桥大学)第五部分
  4. 【干货】从点击率预估的视角看腾讯社交广告算法大赛
  5. jieba源码分析(二)
  6. python中右对齐_python中如何右对齐-问答-阿里云开发者社区-阿里云
  7. python切面编程_python编程上可九天揽月,下可五洋捉鳖,10行代码进行图像识别...
  8. 个性屏幕保护程序_Mac高清鸟瞰屏幕保护程序,酷毙了
  9. python十大装b语法_Python 十大语法
  10. input不管用 vue_重读 VUE 官方文档 lt;2gt;