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

Android studio實(shí)現(xiàn)簡易的計(jì)算器功能

 更新時(shí)間:2022年05月20日 16:44:22   作者:dym_lyy  
這篇文章主要為大家詳細(xì)介紹了Android studio實(shí)現(xiàn)簡易的計(jì)算器功能,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

本文實(shí)例為大家分享了android studio簡易運(yùn)算器,供大家參考,具體內(nèi)容如下

JAVA語句代碼塊:

package com.example.douyingming;

import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.Button;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.RadioGroup.OnCheckedChangeListener;
import android.widget.TextView;
import android.view.View;
import android.view.View.OnClickListener;

public class CompuActivity extends AppCompatActivity implements OnClickListener {
? ? private ?String opr="+"; ?//記錄當(dāng)前運(yùn)算符,最初運(yùn)算符為+,可以更改
? ? private EditText et1,et2;
? ? private TextView tv;
? ? private Button bt;
? ? private RadioGroup rg;
? ? @Override
? ? protected void onCreate(Bundle savedInstanceState) {
? ? ? ? super.onCreate(savedInstanceState);
? ? ? ? setContentView(R.layout.samplecompu); ? ? ? ? ? ?//設(shè)置匹配頁面為samplecompu
? ? ? ? rg=(RadioGroup)findViewById(R.id.radioGroup1); //單選按鈕組的按鈕匹配
? ? ? ? et1=(EditText)findViewById(R.id.editText1);//匹配第一個(gè)編輯框的按鈕
? ? ? ? et2=(EditText)findViewById(R.id.editText2);//匹配第二個(gè)編輯框的按鈕
? ? ? ? tv=(TextView)findViewById(R.id.textView1);//匹配顯示文本

? ? ? ? bt=(Button)findViewById(R.id.button1);//獲得按鈕
? ? ? ? bt.setOnClickListener(this); ? //設(shè)置計(jì)算按鈕的監(jiān)聽器
? ? ? ? rg.setOnCheckedChangeListener(new OnCheckedChangeListener(){ ? ?//設(shè)置單選按鈕監(jiān)聽器,獲得單擊時(shí)執(zhí)行
? ? ? ? ? ? @Override
? ? ? ? ? ? public void onCheckedChanged(RadioGroup group,int checkedId){
? ? ? ? ? ? ? ? // TODO Auto-generated method stub
? ? ? ? ? ? ? ? RadioButton rb=(RadioButton)findViewById(checkedId); //設(shè)定RadioButton類rb,獲得checkedId
? ? ? ? ? ? ? ? opr=rb.getText().toString(); ?//把rb強(qiáng)轉(zhuǎn)為String類型,賦給opr
? ? ? ? ? ? }
? ? ? ? });
? ? }
? ? @Override
? ? public void onClick(View v){ ? ? //定義點(diǎn)擊事件方法
? ? ? ? int sum,num1,num2; ? ? ? ? ? ? //定義三個(gè)變量
? ? ? ? num1 = Integer.parseInt(et1.getText().toString());//接收et1文本框中的數(shù)字(強(qiáng)轉(zhuǎn)為數(shù)字類型)
? ? ? ? num2=Integer.parseInt(et2.getText().toString());//接收et2文本框中的數(shù)字(強(qiáng)轉(zhuǎn)為數(shù)字類型)
? ? ? ? if (opr.equals("+")){ ? ?//+法
? ? ? ? ? ? sum=num1+num2;
? ? ? ? }else if (opr.equals("-")){//減法
? ? ? ? ? ? sum=num1-num2;
? ? ? ? }else if(opr.equals("*")){//乘法
? ? ? ? ? ? sum=num1*num2;
? ? ? ? }else{//如果不是加減乘,就執(zhí)行除法
? ? ? ? ? ? sum=num1/num2;
? ? ? ? }
? ? ? ? tv.setText(String.valueOf(sum)); ?//顯示setText文本


? ? }


}

xml代碼塊

<?xml version="1.0" encoding="utf-8"?>
<!--
設(shè)置布局為垂直
-->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
? ? android:layout_width="match_parent"
? ? android:layout_height="match_parent"
? ? android:orientation="vertical">
? ? <!--
? ? 增加id為editText1
? ? 寬度剛度匹配自己
? ? 文本顯示寬度為8
? ? *
? ? 輸入的類型為數(shù)字
? ? 設(shè)置該文本框焦點(diǎn)
? ? -->

? ? <EditText
? ? ? ? android:id="@+id/editText1"
? ? ? ? android:layout_width="wrap_content"
? ? ? ? android:layout_height="wrap_content"
? ? ? ? android:ems="8"
? ? ? ? android:hint="請(qǐng)輸入數(shù)字"
? ? ? ? android:inputType="number"
? ? ? ? android:text="">
? ? ? ? <requestFocus/>
? ? </EditText>
? ? <!-- 設(shè)置一個(gè)RadioGroup組
? ? 增加一個(gè)id
? ? 寬度匹配父類
? ? 高度等于自己
? ? 該組水平排列
? ? -->
? ? <RadioGroup
? ? ? ? android:id="@+id/radioGroup1"
? ? ? ? android:layout_width="match_parent"
? ? ? ? android:layout_height="wrap_content"
? ? ? ? android:orientation="horizontal">
? ? ? ? <!--
? ? ? ? 增加id
? ? ? ? 寬和高自己匹配
? ? ? ? 選擇為選中狀態(tài)
? ? ? ? 文本內(nèi)容為+
? ? ? ? (四個(gè)RadioButton內(nèi)容相同)
? ? ? ? -->
? ? ? ? <RadioButton
? ? ? ? ? ? android:id="@+id/radio0"
? ? ? ? ? ? android:layout_width="wrap_content"
? ? ? ? ? ? android:layout_height="wrap_content"
? ? ? ? ? ? android:checked="true"
? ? ? ? ? ? android:text="+"/>
? ? ? ? <RadioButton
? ? ? ? ? ? android:id="@+id/radio1"
? ? ? ? ? ? android:layout_width="wrap_content"
? ? ? ? ? ? android:layout_height="wrap_content"
? ? ? ? ? ? android:checked="true"
? ? ? ? ? ? android:text="-"/>
? ? ? ? <RadioButton
? ? ? ? ? ? android:id="@+id/radio2"
? ? ? ? ? ? android:layout_width="wrap_content"
? ? ? ? ? ? android:layout_height="wrap_content"
? ? ? ? ? ? android:checked="true"
? ? ? ? ? ? android:text="*"/>
? ? ? ? <RadioButton
? ? ? ? ? ? android:id="@+id/radio3"
? ? ? ? ? ? android:layout_width="wrap_content"
? ? ? ? ? ? android:layout_height="wrap_content"
? ? ? ? ? ? android:checked="true"
? ? ? ? ? ? android:text="/"/>
? ? </RadioGroup>
? ? <!--
? ? 增加id為editText2
? ? 寬度剛度匹配自己
? ? 文本顯示寬度為8
? ? *
? ? 輸入的類型為數(shù)字
? ? -->
? ? <EditText
? ? ? ? android:id="@+id/editText2"
? ? ? ? android:layout_width="wrap_content"
? ? ? ? android:layout_height="wrap_content"
? ? ? ? android:ems="8"
? ? ? ? android:hint="請(qǐng)輸入數(shù)2"
? ? ? ? android:inputType="number"
? ? ? ? android:text=""/>
? ? <!--
? ? *
? ? 文本為=
? ? -->
? ? <Button
? ? ? ? android:id="@+id/button1"
? ? ? ? android:layout_width="match_parent"
? ? ? ? android:layout_height="wrap_content"
? ? ? ? android:text="="/>
? ? <TextView
? ? ? ? android:id="@+id/textView1"
? ? ? ? android:layout_width="match_parent"
? ? ? ? android:layout_height="wrap_content"
? ? ? ? android:text=""/>
</LinearLayout>

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

相關(guān)文章

  • Retrofit自定義請(qǐng)求參數(shù)注解的實(shí)現(xiàn)思路

    Retrofit自定義請(qǐng)求參數(shù)注解的實(shí)現(xiàn)思路

    這篇文章主要給大家介紹了Retrofit自定義請(qǐng)求參數(shù)注解的實(shí)現(xiàn)思路,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2018-12-12
  • Android實(shí)現(xiàn)微信搖骰子游戲

    Android實(shí)現(xiàn)微信搖骰子游戲

    這篇文章主要為大家詳細(xì)介紹了Android實(shí)現(xiàn)微信搖骰子游戲的相關(guān)代碼,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2017-02-02
  • Android開發(fā)之簡單文件管理器實(shí)現(xiàn)方法

    Android開發(fā)之簡單文件管理器實(shí)現(xiàn)方法

    這篇文章主要介紹了Android開發(fā)之簡單文件管理器實(shí)現(xiàn)方法,簡單實(shí)現(xiàn)了Android的文件目錄查看,文件重命名,打開,刪除等功能,需要的朋友可以參考下
    2016-01-01
  • 深入剖析Android消息機(jī)制原理

    深入剖析Android消息機(jī)制原理

    本篇文章主要介紹了Android消息機(jī)制,深入的了解了android的消息機(jī)制,需要的朋友可以了解一下、
    2016-11-11
  • android教程之把自己的應(yīng)用加入到系統(tǒng)分享中

    android教程之把自己的應(yīng)用加入到系統(tǒng)分享中

    在Android系統(tǒng)中打開相冊中的某張圖片, 點(diǎn)擊右上角的分享按鈕會(huì)彈出分享列表, 把自己的應(yīng)用加入到里面來,下面是設(shè)置方法
    2014-02-02
  • Flutter實(shí)現(xiàn)打印功能的示例詳解

    Flutter實(shí)現(xiàn)打印功能的示例詳解

    這篇文章主要為大家詳細(xì)介紹了如何通過?Flutter?實(shí)現(xiàn)調(diào)用打印機(jī)打印的功能,文中的示例代碼講解詳細(xì),感興趣的小伙伴可以跟隨小編一起學(xué)習(xí)一下
    2024-03-03
  • 功能強(qiáng)大的登錄界面Android實(shí)現(xiàn)代碼

    功能強(qiáng)大的登錄界面Android實(shí)現(xiàn)代碼

    這篇文章主要為大家分享了功能強(qiáng)大的登錄界面Android實(shí)現(xiàn)代碼,驗(yàn)證碼制作方法,自帶一鍵刪除功能,用戶名密碼為空時(shí)抖動(dòng)提示效果,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2016-10-10
  • Android 軟引用和弱引用詳解及實(shí)例代碼

    Android 軟引用和弱引用詳解及實(shí)例代碼

    這篇文章主要介紹了Android 軟引用和弱引用詳解的相關(guān)資料,并附實(shí)現(xiàn)實(shí)例代碼,需要的朋友可以參考下
    2016-11-11
  • 深入了解Android中GestureDetector的定義與使用

    深入了解Android中GestureDetector的定義與使用

    Android中的GestureDetector?可以使用?MotionEvents?檢測各種手勢和事件,非常的好用。本文將會(huì)通過幾個(gè)具體的例子來講解一下GestureDetector的具體使用方法,需要的可以參考一下
    2023-01-01
  • Android微信端的下拉刷新功能

    Android微信端的下拉刷新功能

    在微信公眾號(hào)內(nèi),在面對(duì)下拉刷新這個(gè)問題上,Android和iOS都自己的表現(xiàn)方式。下面通過本文給大家分享Android微信端的下拉刷新功能,需要的朋友參考下吧
    2017-06-06

最新評(píng)論

沧州市| 绍兴市| 绥江县| 林周县| 治县。| 通江县| 饶阳县| 大兴区| 黄浦区| 京山县| 麻城市| 三明市| 桓台县| 舞阳县| 洛阳市| 萍乡市| 家居| 布尔津县| 贵溪市| 海城市| 中卫市| 开远市| 宝兴县| 靖西县| 宁津县| 固阳县| 凭祥市| 忻州市| 武宣县| 迁西县| 来宾市| 内丘县| 洛宁县| 武威市| 阳新县| 买车| 平邑县| 奇台县| 青岛市| 太仆寺旗| 梧州市|