计算器小应用

package com.example.myhomework2;

import androidx.appcompat.app.AppCompatActivity;
import android.app.ProgressDialog;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView; public class MainActivity extends AppCompatActivity{ double num1 = 0 , num2 = 0 , result = 0;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main); } public void click(View v){ EditText et1 = findViewById(R.id.et1);
EditText et2 = findViewById(R.id.et2); num1 = Double.parseDouble(et1.getText().toString());
num2 = Double.parseDouble(et2.getText().toString()); switch (v.getId())
{
case R.id.btn1:
result = num1 + num2;
break;
case R.id.btn2:
result = num1 - num2;
break;
case R.id.btn3:
result = num1 * num2;
break;
case R.id.btn4:
result = num1 / num2;
break;
} } public void click1(View v){ TextView tv1 = findViewById(R.id.tv); /* @setProgress 设置初始进度
* @setProgressStyle 设置样式(水平进度条)
* @setMax 设置进度最大值
*/
final int Max = 100;
final ProgressDialog progressDialog = new ProgressDialog(MainActivity.this);
progressDialog.setProgress(0);
progressDialog.setTitle("正在计算,请稍等...");
progressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
progressDialog.setMax(Max);
progressDialog.show();
/**
* 开个线程
*/
new Thread(new Runnable() {
@Override
public void run() {
int p = 0;
while (p <= Max){
try {
Thread.sleep(10);
p++;
progressDialog.setProgress(p);
}catch (Exception e){
e.printStackTrace();
}
}
progressDialog.cancel();//达到最大就消失
} }).start(); tv1.setText("计算结果:" + result + ""); } public void click2(View v){
EditText et1 = findViewById(R.id.et1);
EditText et2 = findViewById(R.id.et2);
TextView tv = findViewById(R.id.tv);
et1.setText("");
et2.setText("");
tv.setText("");
} }

  

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#789878"> <EditText
android:id="@+id/et1"
android:layout_width="match_parent"
android:layout_height="wrap_content" /> <EditText
android:id="@+id/et2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/et1" /> <Button
android:id="@+id/btn1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/et2"
android:onClick="click"
android:text="+" /> <Button
android:id="@+id/btn2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/et2"
android:layout_toRightOf="@id/btn1"
android:onClick="click"
android:text="-" /> <Button
android:id="@+id/btn3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/et2"
android:layout_toRightOf="@id/btn2"
android:onClick="click"
android:text="*" /> <Button
android:id="@+id/btn4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/et2"
android:layout_toRightOf="@id/btn3"
android:onClick="click"
android:text="/" /> <Button
android:id="@+id/btn5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="计算"
android:textColor="#025588"
android:background="#895865"
android:layout_below="@id/btn1"
android:layout_marginLeft="20dp"
android:onClick="click1"
/> <Button
android:id="@+id/btn6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="清空"
android:textColor="#025588"
android:background="#895865"
android:layout_below="@id/btn4"
android:layout_toRightOf="@id/btn5"
android:layout_marginLeft="135dp"
android:onClick="click2"
/> <TextView
android:id="@+id/tv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/btn5"
android:layout_marginTop="20dp"
android:layout_marginLeft="20dp"
android:text="计算结果:"
/> </RelativeLayout>

  

Android作业 0923的更多相关文章

  1. Android作业分组与选题

    期末大作业 序号 题目 组员分工 完成度 1 基于安卓系统的游戏开发 2 设计一个安卓手机小游戏 3 Android平台应用——音乐播放器设计 4 基于Android技术的个人博客 5 电子阅读器 6 ...

  2. 简单计算器 安卓 Android 作业

    Android老师布置的课程作业——简单计算器 功能要求实现四则运算,参考界面见下图: 首先给各位老铁提供apk安装包以及项目压缩包,略表诚意~ github地址:https://github.com ...

  3. Android作业list

    作业1. 请在自己的电脑上完成Android的安装与配置,并完成Hello Android项目.上交自己与项目的合照,将照片传至QQ群中. ------------------------------ ...

  4. Android作业

    一.设置跑马灯功能   使用滚动字幕显示标题“请选择你喜欢哪种花” <?xml version="1.0" encoding="utf-8"?>&l ...

  5. Android作业0930

    1.使用ListView和Adapter实现购物商城 Android 布局文件 <?xml version="1.0" encoding="utf-8"? ...

  6. Android作业10/07

    1.多个Activity界面实现数据的传递 <?xml version="1.0" encoding="utf-8"?> <androidx. ...

  7. 错误提示”void is an invalid type for the variable“

    今晚做android作业,出现错误提示:void is an invalid type for the variable, invalid:无效的  variable:变量,在网上找了一下后知道是 方 ...

  8. Android——手机内部文件存储(作业)

    作业:把用户的注册信息存储到文件里,登录成功后读出并显示出来 activity_practice2的layout文件: <?xml version="1.0" encodin ...

  9. Android——SharedPreferences存储(作业)

    作业:制作一个登录界面,以SP方式存储用户名.用户下次登录时自动显示上次填写的用户名 layout文件: <?xml version="1.0" encoding=" ...

随机推荐

  1. python 列表和字典的引用与复制(copy)

    列表或字典的引用: 引用针对变量的时候,传递引用后,对引用后的对象的值进行改变是不会影响到原值的:而列表不一样如: spam =42 cheese = spam spam =100 print(spa ...

  2. LG P4161 [SCOI2009]游戏/LG P6280 [USACO20OPEN]Exercise G

    Description(P4161) windy学会了一种游戏. 对于1到N这N个数字,都有唯一且不同的1到N的数字与之对应. 最开始windy把数字按顺序1,2,3,……,N写一排在纸上. 然后再在 ...

  3. Redis入门--进阶详解

    Redis NoSql入门和概述 入门概述 互联网时代背景下大机遇,为什么用nosql 1.单机MySQL的美好年代 在90年代,一个网站的访问量一般都不大,用单个数据库完全可以轻松应付,在那个时候, ...

  4. 国内几大seo高手(夫唯,王通,久久)的技术分析

    http://www.wocaoseo.com/thread-146-1-1.html 目前学习seo的人越来越多了,这种技术的普及和推广也在不断的扩大,先进的好的培训机构不断涌现,很多高水平老师都在 ...

  5. 性能提升40%: 腾讯 TKE 用 eBPF 绕过 conntrack 优化 K8s Service

    Kubernetes Service 用于实现集群中业务之间的互相调用和负载均衡,目前社区的实现主要有userspace,iptables和IPVS三种模式.IPVS模式的性能最好,但依然有优化的空间 ...

  6. 万字长文,Python数据分析实战,使用Pandas进行数据分析

    文章目录 很多人学习python,不知道从何学起.很多人学习python,掌握了基本语法过后,不知道在哪里寻找案例上手.很多已经做案例的人,却不知道如何去学习更加高深的知识.那么针对这三类人,我给大家 ...

  7. Apache 顶级项目 Apache Pulsar 成长回顾

    关于 Apache Pulsar Apache Pulsar 是 Apache 软件基金会顶级项目,是下一代云原生分布式消息流平台,集消息.存储.轻量化函数式计算为一体,采用计算与存储分离架构设计,支 ...

  8. iOS打电话功能的简单实现

    小功能简介 iOS中的很多小功能都是非常简单的,几行代码就搞定了,比如打电话.打开网址.发邮件.发短信等 打电话-方法3 创建一个UIWebView来加载URL,拨完后能自动回到原应用 if (_we ...

  9. 微信小程序授权登录--PHP后端接口

    由于之前做过公众号的一个开发,所以再开发小程序就没有那么多坑了,在这也记录一下开发过程,以方便后续进行参考. 废话不多说,直接上官方文档,任何使用第三方开发的,不看文档就是耍流氓.小程序开发文档,可以 ...

  10. 深入了解Kafka【二】工作流程及文件存储机制

    1.Kafka工作流程 Kafka中的消息以Topic进行分类,生产者与消费者都是面向Topic处理数据. Topic是逻辑上的概念,而Partition是物理上的概念,每个Partition分为多个 ...