小学四则运算口算练习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 ...
随机推荐
- Scala词法文法解析器 (二)分析C++类的声明
最近一直在学习Scala语言,偶然发现其Parser模块功能强大,乃为BNF而设计.啥是BNF,读大学的时候在课本上见过,那时候只觉得这个东西太深奥.没想到所有的计算机语言都是基于BNF而定义的一套规 ...
- linux内核debug的一种方式:procfs
#include <linux/module.h> #include <linux/compat.h> #include <linux/types.h> #incl ...
- Can't locate Math/Round.pm in @INC
遭遇报错: Can't locate Math/Round.pm in @INC 经过亲自测试,下面的命令解决了我的问题. yum install perl-Math-Round 参考资料 ===== ...
- 数据库的dml、ddl和dcl的概念
学过数据库肯定会知道DML.DDL和DCL这三种语言,这种基础概念性的东西是必须要记住的. DML(Data Manipulation Lanaguage,数据操纵语言) DML就是我们经常用到的SE ...
- golang ---timeb
golang 提供了以下两种基础类型 - 时间点(Time) - 时间段(Duration) 除此之外 golang 也提供了以下类型,做一些特定的业务 - 时区(Location) - Ticker ...
- 2019-11-29-dotnet-通过-WMI-获取指定进程的输入命令行
原文:2019-11-29-dotnet-通过-WMI-获取指定进程的输入命令行 title author date CreateTime categories dotnet 通过 WMI 获取指定进 ...
- c# 类实例序列化反序列化json文件 (原发布 csdn 2017-10-01 20:02:12)
前言 前段时间使用了net.json保存对象数据.添加完成后,测试发现300多实例数据保存加载json文件,速度比原方式(BinaryFormatter)慢.但是功能加上后也懒再删掉代码了,索性就采用 ...
- 理解了quote和 symbol-list的 关系
'x === (quote x) '(x) === (list 'x)
- 恭喜你!看到这6个MES系统选型的大坑,千万要避免!
随着工业4.0概念的出现,智能化生产成为了各大制造业的发展趋势! MES系统可以为企业提供包括制造数据管理.计划排程管理.生产调度管理.库存管理.质量管理.人力资源管理.工作中心/设备管理.工具工装管 ...
- Android 可单选多选的任意层级树形控件
花了几天研究了下鸿扬大神的博客<Android打造任意层级树形控件,考验你的数据结构和设计>,再结合公司项目改造改造,现在做个笔记. 先看看Demo的实现效果.首先看的是多选效果 再看看单 ...