android 选择答题功能,Android APP编写简单答题器
本文为大家分享了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 选择答题功能,Android APP编写简单答题器相关推荐
- android开发答题app,Android APP编写简单答题器
本文为大家分享了Android APP编写的简单答题器,此答题器可以通过Next按钮选择下一题,新写题目的类Question,有两个成员变量. java代码: package com.android. ...
- android 选择答题功能,Android实现简单的答题系统
本文实例为大家分享了Android实现答题系统的具体代码,供大家参考,具体内容如下 Question: package com.example.lenovo.exam; /** * Created b ...
- android选择头像弹窗,Android App开发常用功能之用户头像选择-Go语言中文社区
前言 现在的APP基本都有个人资料的填写,基本的都有头像的选择,支持拍照和从本地相册选择,剪切圆形头像的功能,现在用个小demo实现以下. 下面看一下效果图 上代码: 主界面代码 package co ...
- android播放mp3功能,Android Studio实现简单音乐播放功能的示例代码
项目要求 基于Broadcast,BroadcastReceiver等与广播相关的知识实现简单的音乐播放功能,包括音乐的播放.暂停.切换.进度选择.音量调整. 设计效果 (进度条时间刷新功能还没有实现 ...
- android实现打电话功能,Android之简单实现拨打电话功能的方法
手机在我们的日常生活中是最常见的,它的功能是拨打电话和发送短信,那么在Android开发中,我们如何通过该程序拨打电话呢?爱站技术频道给出了Android之简单实现拨打电话功能的方法,一起来看看吧! ...
- android裁剪图片功能,Android实现拍照、选择图片并裁剪图片功能
一. 实现拍照.选择图片并裁剪图片效果 按照之前博客的风格,首先看下实现效果. 二. uCrop项目应用 想起之前看到的Yalantis/uCrop效果比较绚,但是研究源码之后发现在定制界面方面还是有 ...
- android 微信相册功能,Android仿微信选择图片和拍照功能
本文实例为大家分享了 Android微信选择图片的具体代码,和微信拍照功能,供大家参考,具体内容如下 1.Android6.0系统,对于权限的使用都是需要申请,选择图片和拍照需要申请Manifest. ...
- android c聊天功能,Android实现简单C/S聊天室应用
Android的网络应用:简单的C/S聊天室,供大家参考,具体内容如下 服务器端:提供两个类 创建ServerSocket监听的主类:MyServer.java 负责处理每个Socket通信的线程类: ...
- android中英文切换功能,Android APP 中英文切换
实习期间,师父要求做app的中英文切换,就顺便记录了下. 一.AndroidManifest.xml文件(清单文件) 在每个要切换语言的Activity下面添加: android:configChan ...
最新文章
- ArcIMS .NET Link的开发配置
- PM们,请避免对产品的过度解读!
- 数据库系统 - 范式
- 美团面试题:Hashmap的结构,1.7和1.8有哪些区别,深入的分析
- 国民财商教育白皮书(2021年)
- python sys.modules
- multipartfile上传文件_Feign文件上传和部分源码解读
- c语言文件修改某一行,利用C语言替换文件中某一行的方法
- 微服务架构的链路追踪和故障快速排查zipkin(微服务治理)
- “物联网开发实战”学习笔记-(一)硬件开发环境的搭建
- Fluent 三种初始化使用方法
- 【ICnet2018】ICNet for Real-Time Semantic Segmentation on High-Resolution Images
- 软件是如何做到控制芯片电路的闭合的?
- ProxySQL 入门教程
- BZOJ 1050: [HAOI2006]旅行comf
- 低功耗设计(low power design)和UPF介绍(含代码示例)
- Unity引擎中的C#语言学习的笔记(1)
- maven-assembly-plugin插件
- VQA_v2数据集预处理
- 【QMK键盘】简单的QMK固件键盘环境搭建