Android作业 0923
计算器小应用
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的更多相关文章
- Android作业分组与选题
期末大作业 序号 题目 组员分工 完成度 1 基于安卓系统的游戏开发 2 设计一个安卓手机小游戏 3 Android平台应用——音乐播放器设计 4 基于Android技术的个人博客 5 电子阅读器 6 ...
- 简单计算器 安卓 Android 作业
Android老师布置的课程作业——简单计算器 功能要求实现四则运算,参考界面见下图: 首先给各位老铁提供apk安装包以及项目压缩包,略表诚意~ github地址:https://github.com ...
- Android作业list
作业1. 请在自己的电脑上完成Android的安装与配置,并完成Hello Android项目.上交自己与项目的合照,将照片传至QQ群中. ------------------------------ ...
- Android作业
一.设置跑马灯功能 使用滚动字幕显示标题“请选择你喜欢哪种花” <?xml version="1.0" encoding="utf-8"?>&l ...
- Android作业0930
1.使用ListView和Adapter实现购物商城 Android 布局文件 <?xml version="1.0" encoding="utf-8"? ...
- Android作业10/07
1.多个Activity界面实现数据的传递 <?xml version="1.0" encoding="utf-8"?> <androidx. ...
- 错误提示”void is an invalid type for the variable“
今晚做android作业,出现错误提示:void is an invalid type for the variable, invalid:无效的 variable:变量,在网上找了一下后知道是 方 ...
- Android——手机内部文件存储(作业)
作业:把用户的注册信息存储到文件里,登录成功后读出并显示出来 activity_practice2的layout文件: <?xml version="1.0" encodin ...
- Android——SharedPreferences存储(作业)
作业:制作一个登录界面,以SP方式存储用户名.用户下次登录时自动显示上次填写的用户名 layout文件: <?xml version="1.0" encoding=" ...
随机推荐
- 操作系统-I/O(3)SPOOLing技术
为了缓和CPU的高速性与I/O设备低速性间的矛盾而引入了脱机输入.输出技术.该技术是利用专门的外围控制机,将低速I/O设备上的数据传送到高速磁盘上:或者相反. 事实上,当系统中引入了多道程序技术后,完 ...
- 技术揭秘:华为云DLI背后的核心计算引擎
摘要:介绍隐藏在华为云数据湖探索服务背后的核心计算引擎Spark,玩转DLI,,轻松完成大数据的分析处理. 本文主要给大家介绍隐藏在华为云数据湖探索服务(后文简称DLI)背后的核心计算引擎——Spar ...
- ASP.NET Core3.1使用IdentityServer4中间件系列随笔(一):搭建认证服务器
配套源码:https://gitee.com/jardeng/IdentitySolution 1.创建ASP.NET Core Web应用程序,选择空模板. 去掉HTTPS 2.添加nuget包:I ...
- vue刷新数组
困扰我两天的问题被一行代码解决了!!! 最近在做某个功能时用到了v-for,页面内容都是根据父页面传递过来的数组生成的,但是当我改变数组内容时页面不会跟着改变.这个问题足足困扰了我两天时间,最终下面的 ...
- 喵的Unity游戏开发之路 - 游泳
原文: https://mp.weixin.qq.com/s/-ERFNB1GRZ6UAkHOhP9UQw 很多童鞋没有系统的Unity3D游戏开发基础,也不知道从何开始学.为此我们精选了一套国外优秀 ...
- 【Gin-API系列】实现路由分组(七)
在之前的文章介绍中我们已经完成了一个API服务的全链路请求设计.调用方式可以看Test目录的代码 // src/test/request_test.go func TestAPI_Request(t ...
- vue问题整理
生命周期面试题 1.什么是 vue 生命周期 vue 实例从创建到销毁的过程就是生命周期. 也就是从开始创建.初始化数据.编译模板.挂在 dom -> 渲染.更新 -> 渲染.卸载等一系列 ...
- [01] C#网络编程的最佳实践
网络框架的选择 C++语言里面有asio和libuv等网络库, 可以方便的进行各种高效编程. 但是C#里面, 情况不太一样, C#自带的网络API有多种. 例如: Socket TcpStream(同 ...
- C:算术表达式求值
代码: // fgets2.cpp : 定义控制台应用程序的入口点. // #include "stdafx.h" #include <stdio.h> #includ ...
- 跨年夜问题:一句并不复杂的delete竟然在delete statement处cost飙升,在数据量上升的十万级就像进入了死循环,执行后久久没有结果
笔者使用的环境: # 类别 版本 1 操作系统 Win10 2 数据库 Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bi ...