小学四则运算口算练习app---No.3
今天主要是实现按照指定的题目出题数目出题。在昨天设置页面的基础上,今天首先要学习的是接收不同页面间的参数问题。详解如下:

然后就开始我的传参和接收参数的问题!
在当前的Activity上进行跳转,
代码如下:
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.app.AlertDialog;
import android.content.Intent;
import android.widget.TextView;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.content.DialogInterface;
import android.widget.Toast; public class activity_calculators extends AppCompatActivity {
private Button begin;
EditText b,min,sec; @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_calculators);
begin=(Button)findViewById(R.id.button1); b=(EditText)findViewById(R.id.editText2);
min=(EditText)findViewById(R.id.editText3);
sec=(EditText)findViewById(R.id.editText4);
begin.setOnClickListener(new OnClickListener() { @Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
Intent intent=new Intent();
String tishu=b.getText().toString();//获取输入的数值 Bundle bundle = new Bundle();
bundle.putString("tishu", tishu);
intent.putExtras(bundle);//将题目数量传入下一个页面 这是一个方法
intent.setClass(activity_calculators.this, CalculatorActivity.class);//跳转
startActivity(intent);
activity_calculators.this.finish();
}
} 跳转的目标页面的java代码:
CalculatorActivity.class:
import java.util.Random;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
import android.content.Intent;
public class CalculatorActivity extends Activity {
private Random num1=new Random();//随机数生成
private Random num2=new Random();
private Random r = new Random();
private char[] ch = {'+','-','×','÷'};
private int index = r.nextInt(ch.length); //随机数,小于数组的长度数, 0~3
private char a=ch[index];//获取运算符号
private TextView text1,text2,text3;
private EditText answer;
private Button surebutton;
private int i1,i2,i3;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_calculator);
Intent intent = getIntent();
Bundle bundle = intent.getExtras();
String tishu = bundle.getString("tishu");//接收传过来的题目的数量
int i=0;
try {
i = Integer.parseInt(tishu);//i在这里是题目数量的整形值
} catch (NumberFormatException e) {
e.printStackTrace();
}
text1=(TextView)findViewById(R.id.textView1);//随机数字
text2=(TextView)findViewById(R.id.textView2);//运算符号
text3=(TextView)findViewById(R.id.textView3);//随机数字
answer=(EditText)findViewById(R.id.editText1);//运算结果
String c=String.valueOf(num1.nextInt(100));
i2=Integer.valueOf(c);//将产生的数值转换成整形
String d=String.valueOf(a);//运算符
String e=String.valueOf(num2.nextInt(100));
i3=Integer.valueOf(e);//将产生的数值转换成整形
while((d.equals("÷")&&i2%i3!=0)||(d.equals("-")&&i2<i3)||(d.equals("×")&&(i2*i3)>100)||(d.equals("+")&&(i2+i3)>100))
{
text1=(TextView)findViewById(R.id.textView1);//随机数字
text3=(TextView)findViewById(R.id.textView3);//随机数字
c=String.valueOf(num1.nextInt(100));
i2=Integer.valueOf(c);//将产生的数值转换成整形
e=String.valueOf(num2.nextInt(100));
i3=Integer.valueOf(e);//将产生的数值转换成整形
}
text1.setText(c);//随机数1-100 为他们赋值
text2.setText(d);//随机运算符+,-,*,/
text3.setText(e);//随机数1-100 赋值 在手机上显示出来
surebutton=(Button)findViewById(R.id.surebutton);//确定按钮
surebutton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
final String b=answer.getText().toString();//获取输入的数值
i1=Integer.valueOf(b);//将获取的值转换成整形
switch(index){//index是上面判断是数组中哪个运算符的
case 0:
{
if(i1==(i2+i3))
Toast.makeText(CalculatorActivity.this, "正确,答案为"+b, Toast.LENGTH_SHORT).show();
else
Toast.makeText(CalculatorActivity.this, "错误,正确答案为"+(i3+i2), Toast.LENGTH_SHORT).show();
break;
}
case 1:
{
if(i1==(i2-i3))
Toast.makeText(CalculatorActivity.this, "正确,答案为"+b, Toast.LENGTH_SHORT).show();
else
Toast.makeText(CalculatorActivity.this, "错误,正确答案为"+(i2-i3), Toast.LENGTH_SHORT).show();
break;
}
case 2:{
if(i1==(i2*i3))
Toast.makeText(CalculatorActivity.this, "正确,答案为"+b, Toast.LENGTH_SHORT).show();
else
Toast.makeText(CalculatorActivity.this, "错误,正确答案为"+(i2*i3), Toast.LENGTH_SHORT).show();
break;
}
case 3:
{
if(i3!=0){
if(i1==((double)i2/(double)i3))
Toast.makeText(CalculatorActivity.this, "正确,答案为"+b, Toast.LENGTH_SHORT).show();
else
Toast.makeText(CalculatorActivity.this, "错误,正确答案为"+((double)i2/(double)i3), Toast.LENGTH_SHORT).show();
}
break;
}
}
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.calculator, menu);
return true;
}
}
目前只能做到这个效果,还要把横线改位置!

小学四则运算口算练习app---No.3的更多相关文章
- 小学四则运算口算练习app
目标: 第一次尝试做APP,这次做的东西不是很麻烦,做出一个口算练习的加减乘除的页面,使用者做题,设有答案页,进行核对! 核心部分是出题页面的程序,还有答案页的程序.不设置登录注册页面.冲刺时间:一周 ...
- 小学四则运算口算练习app---No.7
今天主要改了设置页面的提示框以及按钮的闪退问题: activity_calculators .class import android.support.v7.app.AppCompatActivity ...
- 小学四则运算口算练习app---No.6
今天主要解决按钮的闪退问题以及答案页面的设置: (位置问题还是无能为力....) 除此之外加了一些菜单键,右上角 resultActivity.class ; String select=;i< ...
- 小学四则运算口算练习app---No.5
今天主要设置答案页面,主要是出题页面和答案页面之间的传参问题以及答案页面的展示问题!这里运用数组讲出的题目包装成一个String类型数目(包括等号和使用者的作答) 讲正确答案单独包装成一个数组,以及相 ...
- 小学四则运算口算练习app---No.4
今天主要是改了出题页中各个组件的位置以及时间的接收还有时间控制,代码如下:(但是存在一个问题 设置页面点击确定按钮进入出题界面时有时会闪退,未解决!) CalculatorActivity.clas ...
- 小学四则运算口算练习app---No.1
因为对app不是很了解,对环境的配置也不是很舒心,今天主要配置了环境,了解了一些相关app的简单操作以及安卓stdiuo的使用!如下: 我自己连接的自己的手机(还是不要拿自己的手机做测试哦!模拟器虽然 ...
- 小学四则运算口算练习app---No.2
经过昨天的了解,虽然还是很懵,总要下手摸到鼠标来写第一个页面! 这是一开始设置出体数目和时间的页面,使用者根据提示进行相关设置即可! 代码如下: <?xml version="1.0& ...
- 123457123456#2#----com.MCgame.ShuXueKoSuan98--前拼后广--儿童小学数学口算Game-mc22222
com.MCgame.ShuXueKoSuan98--前拼后广--儿童小学数学口算Game-mc
- Android-寒假学习-阶段总结(20集)-口算测试APP
说在前面: 1.视频教程:https://www.bilibili.com/video/av60445113/?spm_id_from=333.788.videocard.0 2.老师的源码:http ...
随机推荐
- mysq-5.7忘记密码修改
一,停止mysql /etc/init.d/mysqld stop 二,启动mysql mysqld_safe --skip-grant-tables 安全模式+免验证启动服务 三,登入mysql服务 ...
- mongodb 系列 ~ mongo 用户验证系列
MongoClientURI connectionString = new MongoClientURI("mongodb://root:****@dds-bp114e3f1fc441342 ...
- springboot mybatis使注解和xml两种方式同时生效
声明:该博客参考了:https://www.jianshu.com/p/53762ac6d31c 如果上面这个博客中的内容已经解决了你的问题,那就不用往下看了,如何按照上面的配置一直报这个异常: or ...
- MySQL事务未提交导致整个表锁死
问题及说明: 当一个SQL事务执行完了,但未COMMIT,后面的SQL想要执行就是被锁,超时结束:报错信息如下: mysql> ERROR 1205 (HY000): Lock wait tim ...
- 【记录】【idea】【mysql】Server returns invalid timezone. Go to 'Advanced' tab and set 'serverTimezone' property manually.解决问题
idea连接mysql报错Server returns invalid timezone. Go to 'Advanced' tab and set 'serverTimezone' property ...
- CW2 Software Maintenance Spec Sheet
CW2 Software Maintenance Spec SheetAcademic Year 2019/2020CW2 is about maintaining and extending a r ...
- spring-session-jdbc 使用
这个文档比较有用了,参考: https://www.cnblogs.com/davidwang456/p/10361550.html>https://www.cnblogs.com/davidw ...
- Appium+python自动化(八)- 初识琵琶女Appium(千呼万唤始出来,犹抱琵琶半遮面)- 下(超详解)
简介 通过上一篇宏哥给各位小伙伴们的引荐,大家移动对这位美女有了深刻的认识,而且她那高超的技艺和婀娜的身姿久久地浮现在你的脑海里,是不是这样呢???不要害羞直接告诉宏哥:是,就对了.宏哥要的就是这个 ...
- R语言构建蛋白质网络并实现GN算法
目录 R语言构建蛋白质网络并实现GN算法 1.蛋白质网络的构建 2.生物网络的模块发现方法 3.模块发现方法实现和图形展示 4.附录:igraph中常用函数 参考链接 R语言构建蛋白质网络并实现GN算 ...
- golang学习笔记 go 相关命令
go build 命令一些可选项的用途和用法 在运行go build命令的时候,默认不会编译目标代码包所依赖的那些代码包.当然,如果被依赖的代码包的归档文件(*.a)不存在,或者源码文件有了变化,那么 ...