APP-计算器
在网课上学习了计算器的制作方法,并自己做了小常识,看完一便后,感觉自己会了,思想也明白了,但是当关掉视频真正开始做的时候会发向许多的问题,自己在前的好多语法用的并不是很熟练,但是反复的查阅资料,观看教程,还是可以完成完成这个项目的开发。
activity_main.xml:
- <?xml version="1.0" encoding="utf-8"?>
- <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
- xmlns:app="http://schemas.android.com/apk/res-auto"
- xmlns:tools="http://schemas.android.com/tools"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:orientation="vertical"
- tools:context=".MainActivity">
- <TextView
- android:id="@+id/tvScreen"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:text=""
- android:gravity="right"
- android:textAppearance="?android:attr/textAppearanceLarge"/>
- <TableLayout
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:layout_weight="1">
- <TableRow
- android:layout_width="fill_parent"
- android:layout_height="wrap_content">
- <Button
- android:id="@+id/btn1"
- android:layout_width="wrap_content"
- android:layout_height="match_parent"
- android:layout_weight="1"
- android:text="1" />
- <Button
- android:id="@+id/btn2"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:text="2"
- android:layout_weight="1"/>
- <Button
- android:id="@+id/btn3"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:text="3"
- android:layout_weight="1"/>
- <Button
- android:id="@+id/btnAdd"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:text="+"
- android:layout_weight="1"/>
- </TableRow>
- <TableRow
- android:layout_width="fill_parent"
- android:layout_height="wrap_content">
- <Button
- android:id="@+id/btn4"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:text="4"
- android:layout_weight="1"/>
- <Button
- android:id="@+id/btn5"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:text="5"
- android:layout_weight="1"/>
- <Button
- android:id="@+id/btn6"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:text="6"
- android:layout_weight="1"/>
- <Button
- android:id="@+id/btnSub"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:text="-"
- android:layout_weight="1"/>
- </TableRow>
- <TableRow
- android:layout_width="fill_parent"
- android:layout_height="wrap_content">
- <Button
- android:id="@+id/btn7"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:text="7"
- android:layout_weight="1"/>
- <Button
- android:id="@+id/btn8"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:text="8"
- android:layout_weight="1"/>
- <Button
- android:id="@+id/btn9"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:text="9"
- android:layout_weight="1"/>
- <Button
- android:id="@+id/btnX"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:text="*"
- android:layout_weight="1"/>
- </TableRow>
- <TableRow
- android:layout_width="fill_parent"
- android:layout_height="wrap_content">
- <Button
- android:id="@+id/btnClear"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:text="C"
- android:layout_weight="1"/>
- <Button
- android:id="@+id/btn0"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:text="0"
- android:layout_weight="1"/>
- <Button
- android:id="@+id/btnResult"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:text="="
- android:layout_weight="1"/>
- <Button
- android:id="@+id/btnDiv"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:text="/"
- android:layout_weight="1"/>
- </TableRow>
- </TableLayout>
- </LinearLayout>
MainActivity.java:
- package com.example.counte;
- import androidx.appcompat.app.AppCompatActivity;
- import android.os.Bundle;
- import android.view.Menu;
- import android.view.View;
- import android.widget.Button;
- import android.widget.TextView;
- import java.util.ArrayList;
- import java.util.List;
- public class MainActivity extends AppCompatActivity {
- private TextView tvScrean;
- private List<item> items=new ArrayList<item>();
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
- tvScrean=(TextView)findViewById((R.id.tvScreen));
- findViewById(R.id.btn0).setOnClickListener((View.OnClickListener) this);
- findViewById(R.id.btn1).setOnClickListener((View.OnClickListener) this);
- findViewById(R.id.btn2).setOnClickListener((View.OnClickListener) this);
- findViewById(R.id.btn3).setOnClickListener((View.OnClickListener) this);
- findViewById(R.id.btn4).setOnClickListener((View.OnClickListener) this);
- findViewById(R.id.btn5).setOnClickListener((View.OnClickListener) this);
- findViewById(R.id.btn6).setOnClickListener((View.OnClickListener) this);
- findViewById(R.id.btn7).setOnClickListener((View.OnClickListener) this);
- findViewById(R.id.btn8).setOnClickListener((View.OnClickListener) this);
- findViewById(R.id.btn9).setOnClickListener((View.OnClickListener) this);
- findViewById(R.id.btnAdd).setOnClickListener((View.OnClickListener) this);
- findViewById(R.id.btnSub).setOnClickListener((View.OnClickListener) this);
- findViewById(R.id.btnX).setOnClickListener((View.OnClickListener) this);
- findViewById(R.id.btnDiv).setOnClickListener((View.OnClickListener) this);
- findViewById(R.id.btnClear).setOnClickListener((View.OnClickListener) this);
- findViewById(R.id.btnResult).setOnClickListener((View.OnClickListener) this);
- }
- public void onClick(View v){
- switch (v.getId()){
- case R.id.btn0:
- tvScrean.append("0");
- break;
- case R.id.btn1:
- tvScrean.append("1");
- break;
- case R.id.btn2:
- tvScrean.append("2");
- break;
- case R.id.btn3:
- tvScrean.append("3");
- break;
- case R.id.btn4:
- tvScrean.append("4");
- break;
- case R.id.btn5:
- tvScrean.append("5");
- break;
- case R.id.btn6:
- tvScrean.append("6");
- break;
- case R.id.btn7:
- tvScrean.append("7");
- break;
- case R.id.btn8:
- tvScrean.append("8");
- break;
- case R.id.btn9:
- tvScrean.append("9");
- break;
- case R.id.btnAdd:
- items.add(new item(Double.parseDouble(tvScrean.getText().toString()),Types.Num));
- check();
- items.add(new item(0,Types.Add));
- tvScrean.setText("");//清空文本
- break;
- case R.id.btnSub:
- items.add(new item(Double.parseDouble(tvScrean.getText().toString()),Types.Num));
- check();
- items.add(new item(0,Types.Sub));
- tvScrean.setText("");//清空文本
- break;
- case R.id.btnX:
- items.add(new item(Double.parseDouble(tvScrean.getText().toString()),Types.Num));
- check();
- items.add(new item(0,Types.X));
- tvScrean.setText("");//清空文本
- break;
- case R.id.btnDiv:
- items.add(new item(Double.parseDouble(tvScrean.getText().toString()),Types.Num));
- check();
- items.add(new item(0,Types.Div));
- tvScrean.setText("");//清空文本
- break;
- case R.id.btnClear:
- tvScrean.setText("");
- items.clear();//数组清空
- break;
- case R.id.btnResult:
- items.add(new item(Double.parseDouble(tvScrean.getText().toString()),Types.Num));
- check();
- tvScrean.setText(items.get(0).value+"");
- items.clear();//清空数组
- break;
- }
- }
- public void check(){
- if(items.size()>=3){
- double a=items.get(0).value;
- double b=items.get(2).value;
- int opt=items.get(1).type;
- items.clear();
- switch (opt){
- case Types.Add:
- items.add(new item(a+b,Types.Num));
- break;
- case Types.Sub:
- items.add(new item(a-b,Types.Num));
- break;
- case Types.X:
- items.add(new item(a*b,Types.Num));
- break;
- case Types.Div:
- items.add(new item(a/b,Types.Num));
- break;
- }
- }
- }
- }
item.java:
- package com.example.counte;
- public class item {
- public item(double value,int type){
- this.value=value;
- this.type=type;
- }
- public double value=0;
- public int type=0;
- }
Types.java:
- package com.example.counte;
- public class Types {
- public static final int Add=1;
- public static final int Sub=2;
- public static final int X=3;
- public static final int Div=4;
- public static final int Num=5;
- }
但其中出现的最为明显的问题:
APP-计算器的更多相关文章
- 第一个安卓app——计算器
几天前,我花了一天时间,结合这段时间所学知识开发出了一个简单的计算器,它由两个TextView和23个Button组成,代码会放在文章结尾. TextView TextView:上面一个TextVie ...
- 复利计算器app发布
复利计算器app发布 抱歉:由于无法实现服务端的持续开启,发布的app仅为简单的单机版,暂时舍弃了c/s版本的一些功能,如:投资动态管理功能. 应用详情博客:请点击这里 apk下载地址1(百度手机助手 ...
- ★房贷计算器 APP
一.目的 1. 这是一个蛮有用的小工具 2. 之前看了很多demo,第一次来完全的自己实现一个APP 3. 完成之后提交 App Store 4. 作为Good Coder的提交审核材料 二.排期 周 ...
- app自动化测试之实战应用(魅族计算器)
模拟魅族计算器加法计算: from appium import webdriver desired_caps = {} desired_caps['deviceName'] = '621QECQ23D ...
- 第一个APP:IOS做简单运算的计算器
步骤: 1.打开Xcode,单机Creat a new Xcode project 2.左边选择ios下Application,右边选择single view Application 3.填写项目名称 ...
- 【IOS开发笔记03-视图相关】简单计算器的实现
UIView 经过前几天的快速学习,我们初步了解的IOS开发的一些知识,中间因为拉的太急,忽略了很多基础知识点,这些知识点单独拿出来学习太过枯燥,我们在今后的项目中再逐步补齐,今天我们来学习APP视图 ...
- App测试
(1)App独特测试点: 客户端兼容性测试:系统版本.不同深度定制的rom.屏幕分辨率.中断测试.安装.卸载.升级.对其他程序的干扰等 需要的一些工具: appnium / lr / jmeter ...
- WWDC 后苹果最新 App Store 审核条款!
WWDC 2016 大会之后,苹果公司发布了四个全新平台:iOS,macOS,watchOS 和 tvOS.并且在此之后,苹果应用商店审核条款也同时进行了更新——貌似不算进行了更新,简直就是重 ...
- Windows下部署Appium教程(Android App自动化测试框架搭建)
摘要: 1,appium是开源的移动端自动化测试框架: 2,appium可以测试原生的.混合的.以及移动端的web项目: 3,appium可以测试ios.android.firefox os: 4,a ...
- 菜鸟学Android编程——简单计算器《一》
菜鸟瞎搞,高手莫进 本人菜鸟一枚,最近在学Android编程,网上看了一些视频教程,于是想着平时手机上的计算器应该很简单,自己何不尝试着做一个呢? 于是就冒冒失失的开撸了. 简单计算器嘛,功能当然很少 ...
随机推荐
- [百度之星]资格赛:IP聚合
保持着也不知道什么情怀,觉得到现在才能发出来.这道题做完之后看了其他人的代码,然后再看我的,不得不说,真是幼稚的很,尤其是输入这一块,都什么跟什么啊. 但相较于之前来说,不像以前慌张了,学会先思考再去 ...
- 全局保存ajax请求到的数据
var menuJson = (function() { var result; $.ajax({ type: 'get', u ...
- Bug 佛祖镇楼
原文链接:https://www.cnblogs.com/xdp-gacl/p/4198935.html // _ooOoo_ // o8888888o // 88" . "88 ...
- 吴裕雄--天生自然C++语言学习笔记:C++ 日期 & 时间
C++ 标准库没有提供所谓的日期类型.C++ 继承了 C 语言用于日期和时间操作的结构和函数.为了使用日期和时间相关的函数和结构,需要在 C++ 程序中引用 <ctime> 头文件. 有四 ...
- 吴裕雄 Bootstrap 前端框架开发——Bootstrap 字体图标(Glyphicons):glyphicon glyphicon-map-marker
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta name ...
- 吴裕雄 Bootstrap 前端框架开发——Bootstrap 字体图标(Glyphicons):glyphicon glyphicon-bold
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta name ...
- 第一篇web框架
第一篇web框架 http协议 web应用和web框架 主 文 http协议 HTTP简介 HTTP协议是Hyper Text Transfer Protocol(超文本传输协议)的缩写,是用于从万维 ...
- [GXYCTF2019]BabyUpload
0x00 知识点 文件类型绕过: Content-Type: image/jpeg apache环境下上传.hatcess 首先上传一个.htaccess内容如下的文件 :SetHandler app ...
- CCCC L3-013. 非常弹的球
题意: 刚上高一的森森为了学好物理,买了一个“非常弹”的球.虽然说是非常弹的球,其实也就是一般的弹力球而已.森森玩了一会儿弹力球后突然想到,假如他在地上用力弹球,球最远能弹到多远去呢?他不太会,你能帮 ...
- jquery实现搜索框从中间向两边扩展(左右放大)
显示效果: 隐藏效果: 前端核心代码如下: <div class="search-icon col-md-2 col-sm-2 col-xs-4 col-md-offset-5 col ...