Android studio开发实现计算器功能
作者:HYJones 发布时间:2022-02-12 19:43:05
标签:Android,studio,计算器
Android移动开发实现简单计算器功能,供大家参考,具体内容如下
前言
android 开发小实验
android 移动开发实现 简易计算器功能
小白也能轻松上手,复制粘贴就可使用
使用工具
Android Studio 或者 intellij idea
首先体验一下结果
预览图
源码
前端页面布局
activity_calculator.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:gravity="center"
? ? ? ? ? ? ? android:orientation="vertical"
? ? ? ? ? ? ? android:background="@drawable/bg2"
> ? <TextView
? ? ? ? android:layout_width="410dp"
? ? ? ? android:layout_height="60dp"
? ? ? ? android:text="计算器"
? ? ? ? android:textSize="35dp"
? ? ? ? android:gravity="center"
? ? ? ? android:background="#A6EFEF"
? ? ? ? >
? ? </TextView>
? ? <TextView
? ? ? ? ? ? android:id="@+id/text_show"
? ? ? ? ? ? android:layout_width="410dp"
? ? ? ? ? ? android:layout_height="80dp"
? ? ? ? ? ? android:background="#EAB9B9"
? ? ? ? ? ? android:textSize="30dp"
? ? />
? ? <EditText
? ? ? ? ? ? android:id="@+id/ediText"
? ? ? ? ? ? android:layout_width="410dp"
? ? ? ? ? ? android:layout_height="70dp"
? ? ? ? ? ? android:layout_marginBottom="10dp"
? ? ? ? ? ? android:background="#EAB9B9"
? ? ? ? ? ? android:editable="false"
? ? ? ? ? ? android:gravity="right|center_vertical"
? ? ? ? ? ? android:paddingRight="20dp"
? ? ? ? ? ? android:hint="请输入数字"
? ? ? ? ? ? android:textSize="30sp"
? ? />
? ? <GridLayout
? ? ? ? ? ? android:layout_width="410dp"
? ? ? ? ? ? android:layout_height="400dp"
? ? ? ? ? ? android:columnCount="5"
? ? ? ? ? ? android:rowCount="6">
? ? ? ? <Button
? ? ? ? ? ? ? ? android:id="@+id/button6"
? ? ? ? ? ? ? ? android:layout_width="80dp"
? ? ? ? ? ? ? ? android:layout_height="wrap_content"
? ? ? ? ? ? ? ? android:text="←"
? ? ? ? ? ? ? ? android:background="#87F4F8"
? ? ? ? ? ? ? ? android:layout_margin="2dp"
? ? ? ? ? ? ? ? android:textSize="20dp"
? ? ? ? />
? ? ? ? <Button
? ? ? ? ? ? ? ? android:id="@+id/button7"
? ? ? ? ? ? ? ? android:layout_width="80dp"
? ? ? ? ? ? ? ? android:layout_height="wrap_content"
? ? ? ? ? ? ? ? android:text="CE"
? ? ? ? ? ? ? ? android:background="#87F4F8"
? ? ? ? ? ? ? ? android:layout_margin="2dp"
? ? ? ? ? ? ? ? android:textSize="20dp"
? ? ? ? />
? ? ? ? <Button
? ? ? ? ? ? ? ? android:id="@+id/button8"
? ? ? ? ? ? ? ? android:layout_width="80dp"
? ? ? ? ? ? ? ? android:layout_height="wrap_content"
? ? ? ? ? ? ? ? android:text="C"
? ? ? ? ? ? ? ? android:background="#87F4F8"
? ? ? ? ? ? ? ? android:layout_margin="2dp"
? ? ? ? ? ? ? ? android:textSize="20dp"
? ? ? ? />
? ? ? ? <Button
? ? ? ? ? ? ? ? android:id="@+id/button9"
? ? ? ? ? ? ? ? android:layout_width="80dp"
? ? ? ? ? ? ? ? android:layout_height="wrap_content"
? ? ? ? ? ? ? ? android:text="±"
? ? ? ? ? ? ? ? android:background="#87F4F8"
? ? ? ? ? ? ? ? android:layout_margin="2dp"
? ? ? ? ? ? ? ? android:textSize="20dp"
? ? ? ? />
? ? ? ? <Button
? ? ? ? ? ? ? ? android:id="@+id/button10"
? ? ? ? ? ? ? ? android:layout_width="80dp"
? ? ? ? ? ? ? ? android:layout_height="wrap_content"
? ? ? ? ? ? ? ? android:text="√"
? ? ? ? ? ? ? ? android:background="#87F4F8"
? ? ? ? ? ? ? ? android:layout_margin="2dp"
? ? ? ? ? ? ? ? android:textSize="20dp"
? ? ? ? />
? ? ? ? <Button
? ? ? ? ? ? ? ? android:id="@+id/nine"
? ? ? ? ? ? ? ? android:layout_width="80dp"
? ? ? ? ? ? ? ? android:layout_height="wrap_content"
? ? ? ? ? ? ? ? android:text="9"
? ? ? ? ? ? ? ? android:background="#87F4F8"
? ? ? ? ? ? ? ? android:layout_margin="2dp"
? ? ? ? ? ? ? ? android:textSize="20dp"
? ? ? ? />
? ? ? ? <Button
? ? ? ? ? ? ? ? android:id="@+id/eight"
? ? ? ? ? ? ? ? android:layout_width="80dp"
? ? ? ? ? ? ? ? android:layout_height="wrap_content"
? ? ? ? ? ? ? ? android:text="8"
? ? ? ? ? ? ? ? android:background="#87F4F8"
? ? ? ? ? ? ? ? android:layout_margin="2dp"
? ? ? ? ? ? ? ? android:textSize="20dp"
? ? ? ? />
? ? ? ? <Button
? ? ? ? ? ? ? ? android:id="@+id/seven"
? ? ? ? ? ? ? ? android:layout_width="80dp"
? ? ? ? ? ? ? ? android:layout_height="wrap_content"
? ? ? ? ? ? ? ? android:text="7"
? ? ? ? ? ? ? ? android:background="#87F4F8"
? ? ? ? ? ? ? ? android:layout_margin="2dp"
? ? ? ? ? ? ? ? android:textSize="20dp"
? ? ? ? />
? ? ? ? <Button
? ? ? ? ? ? ? ? android:id="@+id/divider"
? ? ? ? ? ? ? ? android:layout_width="80dp"
? ? ? ? ? ? ? ? android:layout_height="wrap_content"
? ? ? ? ? ? ? ? android:text="/"
? ? ? ? ? ? ? ? android:background="#87F4F8"
? ? ? ? ? ? ? ? android:layout_margin="2dp"
? ? ? ? ? ? ? ? android:textSize="20dp"
? ? ? ? />
? ? ? ? <Button
? ? ? ? ? ? ? ? android:id="@+id/button15"
? ? ? ? ? ? ? ? android:layout_width="80dp"
? ? ? ? ? ? ? ? android:layout_height="wrap_content"
? ? ? ? ? ? ? ? android:text="%"
? ? ? ? ? ? ? ? android:background="#87F4F8"
? ? ? ? ? ? ? ? android:layout_margin="2dp"
? ? ? ? ? ? ? ? android:textSize="20dp"
? ? ? ? />
? ? ? ? <Button
? ? ? ? ? ? ? ? android:id="@+id/four"
? ? ? ? ? ? ? ? android:layout_width="80dp"
? ? ? ? ? ? ? ? android:layout_height="wrap_content"
? ? ? ? ? ? ? ? android:text="4"
? ? ? ? ? ? ? ? android:background="#87F4F8"
? ? ? ? ? ? ? ? android:layout_margin="2dp"
? ? ? ? ? ? ? ? android:textSize="20dp"
? ? ? ? />
? ? ? ? <Button
? ? ? ? ? ? ? ? android:id="@+id/five"
? ? ? ? ? ? ? ? android:layout_width="80dp"
? ? ? ? ? ? ? ? android:layout_height="wrap_content"
? ? ? ? ? ? ? ? android:text="5"
? ? ? ? ? ? ? ? android:background="#87F4F8"
? ? ? ? ? ? ? ? android:layout_margin="2dp"
? ? ? ? ? ? ? ? android:textSize="20dp"
? ? ? ? />
? ? ? ? <Button
? ? ? ? ? ? ? ? android:id="@+id/six"
? ? ? ? ? ? ? ? android:layout_width="80dp"
? ? ? ? ? ? ? ? android:layout_height="wrap_content"
? ? ? ? ? ? ? ? android:text="6"
? ? ? ? ? ? ? ? android:background="#87F4F8"
? ? ? ? ? ? ? ? android:layout_margin="2dp"
? ? ? ? ? ? ? ? android:textSize="20dp"
? ? ? ? />
? ? ? ? <Button
? ? ? ? ? ? ? ? android:id="@+id/multiply"
? ? ? ? ? ? ? ? android:layout_width="80dp"
? ? ? ? ? ? ? ? android:layout_height="wrap_content"
? ? ? ? ? ? ? ? android:text="*"
? ? ? ? ? ? ? ? android:background="#87F4F8"
? ? ? ? ? ? ? ? android:layout_margin="2dp"
? ? ? ? ? ? ? ? android:textSize="20dp"
? ? ? ? />
? ? ? ? <Button
? ? ? ? ? ? ? ? android:id="@+id/button20"
? ? ? ? ? ? ? ? android:layout_width="80dp"
? ? ? ? ? ? ? ? android:layout_height="wrap_content"
? ? ? ? ? ? ? ? android:text="1/X"
? ? ? ? ? ? ? ? android:background="#87F4F8"
? ? ? ? ? ? ? ? android:layout_margin="2dp"
? ? ? ? ? ? ? ? android:textSize="20dp"
? ? ? ? />
? ? ? ? <Button
? ? ? ? ? ? ? ? android:id="@+id/one"
? ? ? ? ? ? ? ? android:layout_width="80dp"
? ? ? ? ? ? ? ? android:layout_height="wrap_content"
? ? ? ? ? ? ? ? android:text="1"
? ? ? ? ? ? ? ? android:background="#87F4F8"
? ? ? ? ? ? ? ? android:layout_margin="2dp"
? ? ? ? ? ? ? ? android:textSize="20dp"
? ? ? ? />
? ? ? ? <Button
? ? ? ? ? ? ? ? android:id="@+id/two"
? ? ? ? ? ? ? ? android:layout_width="80dp"
? ? ? ? ? ? ? ? android:layout_height="wrap_content"
? ? ? ? ? ? ? ? android:text="2"
? ? ? ? ? ? ? ? android:background="#87F4F8"
? ? ? ? ? ? ? ? android:layout_margin="2dp"
? ? ? ? ? ? ? ? android:textSize="20dp"
? ? ? ? />
? ? ? ? <Button
? ? ? ? ? ? ? ? android:id="@+id/three"
? ? ? ? ? ? ? ? android:layout_width="80dp"
? ? ? ? ? ? ? ? android:layout_height="wrap_content"
? ? ? ? ? ? ? ? android:text="3"
? ? ? ? ? ? ? ? android:background="#87F4F8"
? ? ? ? ? ? ? ? android:layout_margin="2dp"
? ? ? ? ? ? ? ? android:textSize="20dp"
? ? ? ? />
? ? ? ? <Button
? ? ? ? ? ? ? ? android:id="@+id/minus"
? ? ? ? ? ? ? ? android:layout_width="80dp"
? ? ? ? ? ? ? ? android:layout_height="wrap_content"
? ? ? ? ? ? ? ? android:text="-"
? ? ? ? ? ? ? ? android:background="#87F4F8"
? ? ? ? ? ? ? ? android:layout_margin="2dp"
? ? ? ? ? ? ? ? android:textSize="20dp"
? ? ? ? />
? ? ? ? <Button
? ? ? ? ? ? ? ? android:id="@+id/equal"
? ? ? ? ? ? ? ? android:layout_width="80dp"
? ? ? ? ? ? ? ? android:layout_height="100dp"
? ? ? ? ? ? ? ? android:layout_rowSpan="2"
? ? ? ? ? ? ? ? android:text="="
? ? ? ? ? ? ? ? android:background="#87F4F8"
? ? ? ? ? ? ? ? android:layout_margin="2dp"
? ? ? ? ? ? ? ? android:textSize="20dp"
? ? ? ? />
? ? ? ? <Button
? ? ? ? ? ? ? ? android:id="@+id/zero"
? ? ? ? ? ? ? ? android:layout_width="160dp"
? ? ? ? ? ? ? ? android:layout_height="wrap_content"
? ? ? ? ? ? ? ? android:layout_columnSpan="2"
? ? ? ? ? ? ? ? android:text="0"
? ? ? ? ? ? ? ? android:background="#87F4F8"
? ? ? ? ? ? ? ? android:layout_margin="2dp"
? ? ? ? ? ? ? ? android:textSize="20dp"
? ? ? ? />
? ? ? ? <Button
? ? ? ? ? ? ? ? android:id="@+id/point"
? ? ? ? ? ? ? ? android:layout_width="80dp"
? ? ? ? ? ? ? ? android:layout_height="wrap_content"
? ? ? ? ? ? ? ? android:text="."
? ? ? ? ? ? ? ? android:background="#87F4F8"
? ? ? ? ? ? ? ? android:layout_margin="2dp"
? ? ? ? ? ? ? ? android:textSize="20dp"
? ? ? ? />
? ? ? ? <Button
? ? ? ? ? ? ? ? android:id="@+id/add"
? ? ? ? ? ? ? ? android:layout_width="80dp"
? ? ? ? ? ? ? ? android:layout_height="wrap_content"
? ? ? ? ? ? ? ? android:text="+"
? ? ? ? ? ? ? ? android:background="#87F4F8"
? ? ? ? ? ? ? ? android:layout_margin="2dp"
? ? ? ? ? ? ? ? android:textSize="20dp"
? ? ? ? />
? ? </GridLayout>
</LinearLayout>
后端源码
CalculatorActivity.java
package com.example.myappch5;
import android.widget.TextView;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.app.Activity;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
public class CalculatorActivity extends Activity implements View.OnClickListener{
? ? //数字0-9
? ? Button number_0;
? ? Button number_1;
? ? Button number_2;
? ? Button number_3;
? ? Button number_4;
? ? Button number_5;
? ? Button number_6;
? ? Button number_7;
? ? Button number_8;
? ? Button number_9;
? ? //运算符
? ? Button add; ? ? ? ? //+
? ? Button minus; ? ? ? //-
? ? Button mul; ? ? ? ? //*
? ? Button divide; ? ? ?//除
? ? Button equal; ? ? ? //=
? ? Button point; ? ? ? //小数点
? ? //清除
? ? Button det;
? ? boolean clean; ? ? ? ? ? ? ? //清空标识
? ? EditText editText; ? ? ? ? ? //结果显示集
? ? TextView text_show; ? ? ? ? ?//显示计算器文本控件
? ? @Override
? ? protected void onCreate(Bundle savedInstanceState) {
? ? ? ? super.onCreate(savedInstanceState);
? ? ? ? setContentView(R.layout.activity_calculator);
? ? ? ? //数字0——9实例化
? ? ? ? number_0=findViewById(R.id.zero);
? ? ? ? number_1=findViewById(R.id.one);
? ? ? ? number_2=findViewById(R.id.two);
? ? ? ? number_3=findViewById(R.id.three);
? ? ? ? number_4=findViewById(R.id.four);
? ? ? ? number_5=findViewById(R.id.five);
? ? ? ? number_6=findViewById(R.id.six);
? ? ? ? number_7=findViewById(R.id.seven);
? ? ? ? number_8=findViewById(R.id.eight);
? ? ? ? number_9=findViewById(R.id.nine);
? ? ? ? //运算符实例化
? ? ? ? add=findViewById(R.id.add); ? ? ? ?//加
? ? ? ? minus=findViewById(R.id.minus); ? ? ? ? //减
? ? ? ? mul=findViewById(R.id.multiply); ? ? ? ?//乘
? ? ? ? divide=findViewById(R.id.divider); ? ? ?//除
? ? ? ? equal=findViewById(R.id.equal); ? ? ? ? //等
? ? ? ? point=findViewById(R.id.point); ? ? ? ? //小数点
? ? ? ? det=findViewById(R.id.button8); ? ? ? ? //清除
? ? ? ? //结果显示集
? ? ? ? text_show = findViewById(R.id.text_show);
? ? ? ? editText=findViewById(R.id.ediText);
//添加事件点击事件
? ? ? ? // 数字点击事件
? ? ? ? number_0.setOnClickListener( this);
? ? ? ? number_1.setOnClickListener(this);
? ? ? ? number_2.setOnClickListener( this);
? ? ? ? number_3.setOnClickListener( this);
? ? ? ? number_4.setOnClickListener(this);
? ? ? ? number_5.setOnClickListener( this);
? ? ? ? number_6.setOnClickListener( this);
? ? ? ? number_7.setOnClickListener(this);
? ? ? ? number_8.setOnClickListener( this);
? ? ? ? number_9.setOnClickListener( this);
? ? ? ? // 符号点击事件
? ? ? ? add.setOnClickListener( this);
? ? ? ? minus.setOnClickListener( this);
? ? ? ? mul.setOnClickListener( this);
? ? ? ? divide.setOnClickListener( this);
? ? ? ? point.setOnClickListener( this);
? ? ? ? equal.setOnClickListener( this);
? ? ? ? det.setOnClickListener( this);
? ? }
? ? //读取每个按钮内容
? ? public void onClick(View view){
? ? ? ? //获取文本内容
? ? ? ? String ?input=editText.getText().toString();
? ? ? ? switch (view.getId()){
? ? ? ? ? ? case R.id.zero: ? ? // 0
? ? ? ? ? ? case R.id.one: ? ? ?// 1
? ? ? ? ? ? case R.id.two: ? ? ?// 2
? ? ? ? ? ? case R.id.three: ? ?// 3
? ? ? ? ? ? case R.id.four: ? ? // 4
? ? ? ? ? ? case R.id.five: ? ? // 5
? ? ? ? ? ? case R.id.six: ? ? ?// 6
? ? ? ? ? ? case R.id.seven: ? ?// 7
? ? ? ? ? ? case R.id.eight: ? ?// 8
? ? ? ? ? ? case R.id.nine: ? ? // 9
? ? ? ? ? ? case R.id.point: ? ?//小数点
? ? ? ? ? ? ? ? if(clean){
? ? ? ? ? ? ? ? ? ? clean=false;
? ? ? ? ? ? ? ? ? ? editText.setText(""); ? //赋值为空
? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? editText.setText(input+((Button)view).getText()+""); ? ?//结果集就是本身
? ? ? ? ? ? ? ? break;
? ? ? ? ? ? case R.id.add:
? ? ? ? ? ? case R.id.minus: ? ? ? ? ?// 减
? ? ? ? ? ? case R.id.multiply: ? ? ? // 乘
? ? ? ? ? ? case R.id.divider: ? ? ? ?// 除
? ? ? ? ? ? ? ? if(clean){
? ? ? ? ? ? ? ? ? ? clean=false;
? ? ? ? ? ? ? ? ? ? input="";
? ? ? ? ? ? ? ? ? ? editText.setText("");
? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? editText.setText(input+" "+((Button)view).getText()+" ");
? ? ? ? ? ? ? ? break;
? ? ? ? ? ? case R.id.button8: ? ? ?//清除
? ? ? ? ? ? ? ? if(clean){
? ? ? ? ? ? ? ? ? ? clean=false;
? ? ? ? ? ? ? ? ? ? input="";
? ? ? ? ? ? ? ? ? ? editText.setText("");
? ? ? ? ? ? ? ? }else ?if(input!=null || !input.equals("")){
? ? ? ? ? ? ? ? ? ? //如果获取内容为空
? ? ? ? ? ? ? ? ? ? editText.setText(input.substring(0,input.length() - 1 ));//结果集为空
? ? ? ? ? ? ? ? ? ? break;
? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? break;
? ? ? ? ? ? case ?R.id.equal: ? //运算结果=
? ? ? ? ? ? ? ? getResult(); ? ?//调用处理结果方法
? ? ? ? ? ? ? ? break;
? ? ? ? }
? ? }
//运算结果方法
? ? private void getResult(){
? ? ? ? String exp=editText.getText().toString(); ? ? ? //获取文本框内容
? ? ? ? if(exp==null||exp.equals("")){
? ? ? ? ? ? return;
? ? ? ? }
? ? ? ? if(!exp.contains("")){
? ? ? ? ? ? return;
? ? ? ? }
? ? ? ? if(clean){
? ? ? ? ? ? clean=false;
? ? ? ? ? ? return;
? ? ? ? }
? ? ? ? clean=true;
? ? ? ? double result=0;
?//进行截取
? ? ? ? // 运算符前的数字
? ? ? ? String s1=exp.substring(0,exp.indexOf(" "));
? ? ? ? //运算符
? ? ? ? String op=exp.substring(exp.indexOf(" ")+1,exp.indexOf(" ")+2);
? ? ? ? //运算符后的数字
? ? ? ? String s2=exp.substring(exp.indexOf(" ")+3);
? ? ? ? if(!s1.equals("")&&!s2.equals("")){
? ? ? ? ? ? //如果包含小数点的运算
? ? ? ? ? ? double d1=Double.parseDouble(s1);//则数字都是double类型
? ? ? ? ? ? double d2=Double.parseDouble(s2);
? ? ? ? ? ? if(op.equals("+")){
? ? ? ? ? ? ? ? // 如果是+
? ? ? ? ? ? ? ? result=d1+d2;
? ? ? ? ? ? ? ? text_show.setText(d1+ "+" +d2+"=");
? ? ? ? ? ? }else if(op.equals("-")){
? ? ? ? ? ? ? ? //如果是-
? ? ? ? ? ? ? ? result=d1-d2;
? ? ? ? ? ? ? ? text_show.setText(d1+ "-" +d2+"=");
? ? ? ? ? ? }else if(op.equals("*")){
? ? ? ? ? ? ? ? //如果是*
? ? ? ? ? ? ? ? result=d1*d2;
? ? ? ? ? ? ? ? text_show.setText(d1+ "*" +d2+"=");
? ? ? ? ? ? }else if(op.equals("/")){
? ? ? ? ? ? ? ? if(d2==0){
? ? ? ? ? ? ? ? ? ? //如果被除数是0
? ? ? ? ? ? ? ? ? ? result=0;//则结果为0
? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? else {
? ? ? ? ? ? ? ? ? ? //否则执行正常运算
? ? ? ? ? ? ? ? ? ? result=d1/d2;
? ? ? ? ? ? ? ? ? ? text_show.setText(d1+ "/" +d2+"=");
? ? ? ? ? ? ? ? }
? ? ? ? ? ? }
? ? ? ? ? ? if(!s1.contains(".") &&!s2.contains(".")&&!op.equals("/")){
? ? ? ? ? ? ? ? //如果是整数类型
? ? ? ? ? ? ? ? int r=(int)result;//都是整形
? ? ? ? ? ? ? ? editText.setText(r+"");
? ? ? ? ? ? }else {
? ? ? ? ? ? ? ? editText.setText(result+"");
? ? ? ? ? ? }
? ? ? ? }else ?if(!s1.equals("")&& s2.equals("")){
? ? ? ? ? ? //如果只输入运算符前的数字
? ? ? ? ? ? editText.setText(exp);//直接返回当前输入内容
? ? ? ? }else if (s1.equals("")&& !s2.equals("")){
? ? ? ? ? ? //如果是只输入运算符后面的数
? ? ? ? ? ? double d2 =Double.parseDouble(s2);
? ? ? ? ? ? //运算符当前没有输入数字
? ? ? ? ? ? if(op.equals("+")){
? ? ? ? ? ? ? ? result= 0 + d2;
? ? ? ? ? ? ? ? text_show.setText(d2+"=");
? ? ? ? ? ? }else ?if(op.equals("-")){
? ? ? ? ? ? ? ? result= 0 - d2;
? ? ? ? ? ? ? ? text_show.setText(d2+"=");
? ? ? ? ? ? }else if (op.equals("*")){
? ? ? ? ? ? ? ? result= 0;
? ? ? ? ? ? }else ?if(op.equals("/")){
? ? ? ? ? ? ? ? result= 0;
? ? ? ? ? ? }
? ? ? ? ? ? if(!s1.contains(".")&&!s2.contains(".")){
? ? ? ? ? ? ? ? int r=(int) result;
? ? ? ? ? ? ? ? editText.setText(r+"");
? ? ? ? ? ? }else {
? ? ? ? ? ? ? ? editText.setText(result+"");
? ? ? ? ? ? }
? ? ? ? }else {
? ? ? ? ? ? editText.setText("");
? ? ? ? }
? ? }
}
来源:https://blog.csdn.net/hjjshua/article/details/123779110
0
投稿
猜你喜欢
- 表关联上一篇介绍了JPA的简单使用,这一篇介绍JPA在表关联上的使用一对一配置参数JPA对于数据实体一对一映射使用的是@OneToOne注解
- SimpleDateFormat是处理日期格式转换的类。官方API_1.8关于SimpleDateFormat继承于DateFormate截
- 各位早上好,话不多说,先上效果图:注意顶部:首页TextView的变化(显示和隐藏)!首先分析下:UI状态,其是由RecyclerView添
- startActivityForResult与startActivity的不同之处在于:1、startActivity( )仅仅是跳转到目标
- 代码import javax.mail.internet.InternetAddress;import javax.mail.interne
- java中Executor,ExecutorService,ThreadPoolExecutor详解1.Excutor  
- java和javascript长得是如此地相像,那么它们是一回事儿吗?现在让我来揭晓答案吧!JavaScript 是一种嵌入式脚本文件,直接
- 开发过程, 我们习惯把数据源配置, 项目常量, 日志配置等基础数据配置写到一个个单独的的文件中. 如jdbc.properties等各种.格
- 模仿网易新闻客户端阅读偏好的频道选择,先看实现的页面: 直接上代码:import android.content.res.Resources
- 在Unity中实现简单的伪时间同步,只是读取数据库所在电脑的当前时间using UnityEngine;using System.Colle
- 本文实例讲述了C#实现的文件压缩和解压缩类。分享给大家供大家参考。具体分析如下:这个C#代码包含了几个类,封装了文件压缩和解压缩常用的方法,
- 在WinForm程序中,实现TextBox文本输入框占位符的方式也很多,最常用的是方式基于Windows Api SendMessage函数
- 如何在WinForm中请求发送HTTP手工发送HTTP请求主要是调用 System.Net的HttpWebResponse方法手工发送HTT
- springboot html调用js无效400html板在templates下面,js文件在static下面,在模板中引用时不需要加sta
- 题目描述原题链接 :88. 合并两个有序数组给你两个按 非递减顺序 排列的整数数组 nums1 和 nums2,另有两个整数 m
- springcloud集成nacos遇到的问题1.获取不到配置文件信息有时候新建了配置文件后浏览器访问发现获取不到里面的值,原来spring
- 本文实例讲述了C#键盘鼠标钩子的实现方法。分享给大家供大家参考。具体实现方法如下:using System;using System.Col
- 前 言🍉 作者简介:半旧518,长跑型选手,立志坚持写10年博客,专注于java后端☕专栏简介:深入、全面、系统的介绍消息中间件🌰 文章简介
- 本文实例讲述了.NET/C#实现识别用户访问设备的方法。分享给大家供大家参考,具体如下:一、需求需要获取到用户访问网站时使用的设备,根据不同
- idea工具使用 Java Exception Breakpoint 添加异常断点,在IDE里,新建一个断点,类型是Java Excepti