最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Android?studio開發(fā)實現(xiàn)計算器功能

 更新時間:2022年05月20日 10:38:34   作者:HYJones  
這篇文章主要為大家詳細(xì)介紹了Android?studio開發(fā)實現(xiàn)計算器功能,文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下

Android移動開發(fā)實現(xiàn)簡單計算器功能,供大家參考,具體內(nèi)容如下

前言

android 開發(fā)小實驗
android 移動開發(fā)實現(xiàn) 簡易計算器功能
小白也能輕松上手,復(fù)制粘貼就可使用

使用工具

Android Studio 或者 intellij idea

首先體驗一下結(jié)果

預(yù)覽圖

源碼

前端頁面布局

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="請輸入數(shù)字"
? ? ? ? ? ? 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{
? ? //數(shù)字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;

? ? //運(yùn)算符
? ? Button add; ? ? ? ? //+
? ? Button minus; ? ? ? //-
? ? Button mul; ? ? ? ? //*
? ? Button divide; ? ? ?//除
? ? Button equal; ? ? ? //=
? ? Button point; ? ? ? //小數(shù)點

? ? //清除
? ? Button det;

? ? boolean clean; ? ? ? ? ? ? ? //清空標(biāo)識

? ? EditText editText; ? ? ? ? ? //結(jié)果顯示集

? ? TextView text_show; ? ? ? ? ?//顯示計算器文本控件

? ? @Override
? ? protected void onCreate(Bundle savedInstanceState) {
? ? ? ? super.onCreate(savedInstanceState);
? ? ? ? setContentView(R.layout.activity_calculator);
? ? ? ? //數(shù)字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);

? ? ? ? //運(yùn)算符實例化
? ? ? ? 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); ? ? ? ? //小數(shù)點
? ? ? ? det=findViewById(R.id.button8); ? ? ? ? //清除

? ? ? ? //結(jié)果顯示集
? ? ? ? text_show = findViewById(R.id.text_show);
? ? ? ? editText=findViewById(R.id.ediText);
//添加事件點擊事件
? ? ? ? // 數(shù)字點擊事件
? ? ? ? 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);
? ? }

? ? //讀取每個按鈕內(nèi)容
? ? public void onClick(View view){
? ? ? ? //獲取文本內(nèi)容
? ? ? ? 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: ? ?//小數(shù)點
? ? ? ? ? ? ? ? if(clean){
? ? ? ? ? ? ? ? ? ? clean=false;
? ? ? ? ? ? ? ? ? ? editText.setText(""); ? //賦值為空
? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? editText.setText(input+((Button)view).getText()+""); ? ?//結(jié)果集就是本身
? ? ? ? ? ? ? ? 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("")){
? ? ? ? ? ? ? ? ? ? //如果獲取內(nèi)容為空
? ? ? ? ? ? ? ? ? ? editText.setText(input.substring(0,input.length() - 1 ));//結(jié)果集為空
? ? ? ? ? ? ? ? ? ? break;
? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? break;
? ? ? ? ? ? case ?R.id.equal: ? //運(yùn)算結(jié)果=
? ? ? ? ? ? ? ? getResult(); ? ?//調(diào)用處理結(jié)果方法
? ? ? ? ? ? ? ? break;
? ? ? ? }
? ? }
//運(yùn)算結(jié)果方法
? ? private void getResult(){
? ? ? ? String exp=editText.getText().toString(); ? ? ? //獲取文本框內(nèi)容
? ? ? ? if(exp==null||exp.equals("")){
? ? ? ? ? ? return;
? ? ? ? }
? ? ? ? if(!exp.contains("")){
? ? ? ? ? ? return;
? ? ? ? }
? ? ? ? if(clean){
? ? ? ? ? ? clean=false;
? ? ? ? ? ? return;
? ? ? ? }
? ? ? ? clean=true;
? ? ? ? double result=0;
?//進(jìn)行截取
? ? ? ? // 運(yùn)算符前的數(shù)字
? ? ? ? String s1=exp.substring(0,exp.indexOf(" "));
? ? ? ? //運(yùn)算符
? ? ? ? String op=exp.substring(exp.indexOf(" ")+1,exp.indexOf(" ")+2);
? ? ? ? //運(yùn)算符后的數(shù)字
? ? ? ? String s2=exp.substring(exp.indexOf(" ")+3);

? ? ? ? if(!s1.equals("")&&!s2.equals("")){
? ? ? ? ? ? //如果包含小數(shù)點的運(yùn)算
? ? ? ? ? ? double d1=Double.parseDouble(s1);//則數(shù)字都是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){
? ? ? ? ? ? ? ? ? ? //如果被除數(shù)是0
? ? ? ? ? ? ? ? ? ? result=0;//則結(jié)果為0
? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? else {
? ? ? ? ? ? ? ? ? ? //否則執(zhí)行正常運(yùn)算
? ? ? ? ? ? ? ? ? ? result=d1/d2;
? ? ? ? ? ? ? ? ? ? text_show.setText(d1+ "/" +d2+"=");
? ? ? ? ? ? ? ? }
? ? ? ? ? ? }
? ? ? ? ? ? if(!s1.contains(".") &&!s2.contains(".")&&!op.equals("/")){
? ? ? ? ? ? ? ? //如果是整數(shù)類型
? ? ? ? ? ? ? ? int r=(int)result;//都是整形
? ? ? ? ? ? ? ? editText.setText(r+"");
? ? ? ? ? ? }else {
? ? ? ? ? ? ? ? editText.setText(result+"");
? ? ? ? ? ? }
? ? ? ? }else ?if(!s1.equals("")&& s2.equals("")){
? ? ? ? ? ? //如果只輸入運(yùn)算符前的數(shù)字
? ? ? ? ? ? editText.setText(exp);//直接返回當(dāng)前輸入內(nèi)容
? ? ? ? }else if (s1.equals("")&& !s2.equals("")){
? ? ? ? ? ? //如果是只輸入運(yùn)算符后面的數(shù)
? ? ? ? ? ? double d2 =Double.parseDouble(s2);

? ? ? ? ? ? //運(yùn)算符當(dāng)前沒有輸入數(shù)字
? ? ? ? ? ? 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("");
? ? ? ? }
? ? }
}

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • Android NDK 開發(fā)中 SO 包大小壓縮方法詳解

    Android NDK 開發(fā)中 SO 包大小壓縮方法詳解

    這篇文章主要為為大家介紹了Android NDK 開發(fā)中 SO 包大小壓縮方法詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2022-09-09
  • Android自定義封裝banner組件

    Android自定義封裝banner組件

    這篇文章主要為大家詳細(xì)介紹了Android自定義封裝banner組件的相關(guān)資料,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2017-06-06
  • 故事講解Activity生命周期(貓的一生)

    故事講解Activity生命周期(貓的一生)

    關(guān)于Android中Activity的生命周期,網(wǎng)上大多數(shù)文章基本都是直接貼圖、翻譯API,比較籠統(tǒng)含糊不清。本文主要用故事講解Activity生命周期。下面跟著小編一起來看下吧
    2017-03-03
  • Android開發(fā)中Intent用法總結(jié)

    Android開發(fā)中Intent用法總結(jié)

    這篇文章主要介紹了Android開發(fā)中Intent用法,總結(jié)分析了Android中Intent的功能、使用方法與相關(guān)注意事項,需要的朋友可以參考下
    2016-10-10
  • android中開啟actionbar的兩種方法

    android中開啟actionbar的兩種方法

    這篇文章主要介紹了android中開啟actionbar的兩種方法,本文給出了靜態(tài)開啟和動態(tài)開啟2種方法,需要的朋友可以參考下
    2015-06-06
  • 詳解Android中Drawable方法

    詳解Android中Drawable方法

    這篇文章主要為大家詳細(xì)介紹了Android中Drawable方法,感興趣的朋友可以參考一下
    2016-05-05
  • Android用PopupWindow實現(xiàn)自定義Dailog

    Android用PopupWindow實現(xiàn)自定義Dailog

    這篇文章主要為大家詳細(xì)介紹了Android用PopupWindow實現(xiàn)自定義Dailog的相關(guān)資料,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2017-01-01
  • Android自定義View繪圖實現(xiàn)拖影動畫

    Android自定義View繪圖實現(xiàn)拖影動畫

    這篇文章主要介紹了Android自定義View繪圖實現(xiàn)拖影動畫,,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2016-09-09
  • Android仿UC瀏覽器左右上下滾動功能

    Android仿UC瀏覽器左右上下滾動功能

    這篇文章主要介紹了Android仿UC瀏覽器左右上下滾動功能,左右滑動顯示菜單,上下滑動滾動內(nèi)容,需要的朋友可以參考下
    2015-12-12
  • flutter Container容器實現(xiàn)圓角邊框

    flutter Container容器實現(xiàn)圓角邊框

    這篇文章主要為大家詳細(xì)介紹了flutter Container容器實現(xiàn)圓角邊框,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2019-07-07

最新評論

台州市| 甘德县| 巴塘县| 洛浦县| 班玛县| 潼关县| 鄂托克前旗| 合阳县| 阳新县| 响水县| 家居| 于都县| 胶南市| 邹平县| 永修县| 山东| 班玛县| 磴口县| 湘阴县| 凤台县| 石门县| 汶川县| 屏东县| 随州市| 玛多县| 稷山县| 香河县| 宿迁市| 丹棱县| 玛沁县| 任丘市| 屏东市| 西乡县| 湘潭市| 安多县| 炎陵县| 荥阳市| 抚州市| 长寿区| 淄博市| 福鼎市|