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=" ...
随机推荐
- 第5篇 Scrum冲刺博客
1.站立式会议 1.1 会议图片 1.2 项目进展 成员 昨日任务 今日计划完成任务 陈忠明 歌曲信息的上传/下载包 歌曲批量下载压缩包 吴茂平 完善评论系统 新消息提醒功能设计 黄海钊 修改代码规范 ...
- HTTP基础--网页基础
网页的组成: 网页可以分为三大部分---HTML,CSS和JavaScript.如果把网页比作一个人的话,HTML相当于骨架,JavaScript相当于肌肉,CSS相当于皮肤,三者结合起来才能形成一个 ...
- latex:备忘代码
1.脚注代码: \footnote{欧几里德,约公元前330--340年.} 结果为: 2.改变某个字的字体形状,表示强调 \emph{勾股定理} 结果为(勾股数这三个字与其他字不一样): 3.正文中 ...
- 接口测试 Mock 实战 | 结合 jq 完成批量化的手工 Mock
本文霍格沃兹测试学院学员学习实践笔记. 一.应用背景 因为本章的内容是使用jq工具配合完成,因此在开始部分会先花一定的篇幅介绍jq机器使用,如果读者已经熟悉jq,可以直接跳过这部分. 先来看应用场景, ...
- QString 字符串操作
Qt QString字符串分割.截取(转载) 在做项目中不可避免的会使用到一串字符串中的一段字符,因此常常需要截取字符串. 有两种方式可以解决这个问题: 方法一:QString分割字符串: QStri ...
- Spring实战第4版PDF下载含源码
下载链接 扫描右侧公告中二维码,回复[spring实战]即可获取所有链接. 读者评价 看了一半后在做评论,物流速度挺快,正版行货,只是运输过程有点印记,但是想必大家和你关注内容,spring 4必之3 ...
- 无法创建新虚拟机: 无法打开配置文件“F:\BigData\vm12\centos01\centos01.vmx”: 拒绝访问。
退出,右键vmware选择以管理员身份运行即可.
- 如何用python制作贪吃蛇以及AI版贪吃蛇
用python制作普通贪吃蛇 哈喽,大家不知道是上午好还是中午好还是下午好还是晚上好! 很多人学习python,不知道从何学起.很多人学习python,掌握了基本语法过后,不知道在哪里寻找案例上手.很 ...
- War3模型导出
Wiki https://en.wikipedia.org/wiki/.MDX 教程 http://www.ou99.com/article-25996-1.html http://blog.csdn ...
- Codehorses T-shirts (map+遍历)
Codehorses has just hosted the second Codehorses Cup. This year, the same as the previous one, organ ...