小学四则运算口算练习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 ...
随机推荐
- 【2019年07月08日】A股最便宜的股票
查看更多A股最便宜的股票:androidinvest.com/CNValueTop/ 便宜指数 = PE + PB + 股息 + ROE,四因子等权,数值越大代表越低估. 本策略只是根据最新的数据来选 ...
- Leetcode 344:Reverse String 反转字符串(python、java)
Leetcode 344:Reverse String 反转字符串 公众号:爱写bug Write a function that reverses a string. The input strin ...
- Python【每日一问】38
问: 基础题: 设计一个经营杠杆系数函数DOL,它包含三个参数,S为营业收入,C为变动成本总额,F为固定成本的总额. 已知2018年的S为20,C为11,F为3,求2019年的经营杠杆系数. 提高题: ...
- Nginx php上传文件大小的设置
- CAS5单点登录
看这篇文章即可:https://www.jianshu.com/p/c1273d81c4e4>https://www.jianshu.com/p/c1273d81c4e4
- Kubernetes增强型调度器Volcano算法分析【华为云技术分享】
[摘要] Volcano 是基于 Kubernetes 的批处理系统,源自于华为云开源出来的.Volcano 方便 AI.大数据.基因.渲染等诸多行业通用计算框架接入,提供高性能任务调度引擎,高性能异 ...
- springBoot获取@NotBlank,@NotNull注解的message信息
概述 springBoot后台验证接收的参数是否不合法时,会抛出一个BlndException异常,获取message的自定义信息并返回 验证 UserEntity类 @Data @Entity @T ...
- WPF 精修篇 管理资源字典
原文:WPF 精修篇 管理资源字典 样式太多 每个界面可能需要全局的样式 有没有肯能 WPF 中的样式 像Asp.net中 的CSS一样管理那 有的 有资源字典 BurshDictionary &l ...
- 用友U9 查看功能页面实体
对着当前页面右键查看属性: 在链接后面加上&__dm=true 在打开的页面将鼠标放到字段上,可以看到页面实体是那一个.
- angularJS 在edge浏览器上传文件,无法主动触发ng-click
今天发现的问题 在谷歌浏览器一直运行良好的功能,在edge浏览器不能使用. 代码参考我的另一篇博客:WebAPI Angularjs 上传文件 不能运行的原因 下图红框中的代码在edge浏览器中无法执 ...