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=" ...
随机推荐
- Java并发---concurrent包
一.包的结构层次 其中包含了两个子包atomic和locks,另外字concurrent下的阻塞队列以及executor,这些就是concurrent包中的精华.而这些类的实现主要是依赖于volati ...
- Java数据结构——图的DFS和BFS
1.图的DFS: 即Breadth First Search,深度优先搜索是从起始顶点开始,递归访问其所有邻近节点,比如A节点是其第一个邻近节点,而B节点又是A的一个邻近节点,则DFS访问A节点后再访 ...
- 使用Java8中的Optional类来消除代码中的null检查
简介 Optional类是Java 8新增的一个类,Optional 类主要解决的问题是臭名昭著的空指针异常(NullPointerException). —— 每个 Java 程序员都非常了解的异常 ...
- Spring boot程序的部署及运行
将 spring boot 应用程序打包成 jar 包 我们使用 spring boot 的 maven 插件来构建管理整个应用程序,使用 mvn package 将应用程序打包成一个 jar 包 将 ...
- DVWA之文件包含(一)
文件包含又可以是本地文件包含或远程文件包含. 本地文件包含:文件存在本地目录 远程文件包含:文件共享或存在网络上,需要访问 <?php // The page we wish to displa ...
- composer版本号前面`^`和`~`的区别
~1.2.3表示: 1.2.3 <= 版本号 < 1.3.0 ^1.2.3表示: 1.2.3 <= 版本号 < 2.0.0 ~1.2 表示: 1.2.0 <= 版本号 & ...
- Nodejs模块:fs
/** * @description fs模块常用api */ // fs所有的文件操作都是异步IO,如果要以同步的方式去调用,都会加一个在原同步api的基础上加Sync // 同步的方式会在最后传入 ...
- eclipse android程序运行报错:Conversion to Dalvik format failed: Unable to execute dex:
[2013-06-19 16:59:01 - Dex Loader] Unable to execute dex: Multiple dex files define Landroid/support ...
- Cubmap
视差 Cubmap https://chengkehan.github.io/LocalCubmap.html http://www.manew.com/thread-93923-1-1.html h ...
- 大厂运维必备技能:PB级数据仓库性能调优
摘要:众所周知,数据量大了之后,性能是大家关注的一点,所以我们在业务开发的时候,特别关注性能,做为一个架构师,必须对性能要了解,要懂.才能设计出高性能的业务系统. 一.GaussDB分布式架构 所谓集 ...