国产成人精品久久免费动漫-国产成人精品天堂-国产成人精品区在线观看-国产成人精品日本-a级毛片无码免费真人-a级毛片毛片免费观看久潮喷

您的位置:首頁技術文章
文章詳情頁

Android實現兩個數相加功能

瀏覽:68日期:2022-09-25 10:39:59

本文實例為大家分享了Android實現兩個數相加的具體代碼,供大家參考,具體內容如下

要實現如圖所示的加法計算器的話,還是比較簡單的,下面直接上demo,有不懂的可以留言交流。

Android實現兩個數相加功能

1、下面是activity.xml的布局文件

<?xml version='1.0' encoding='utf-8'?> <LinearLayout xmlns:android='http://schemas.android.com/apk/res/android' xmlns:tools='http://schemas.android.com/tools' android:layout_width='match_parent' android:layout_height='match_parent' android:orientation='vertical' tools:context='.MainActivity'> <LinearLayout android:layout_width='match_parent' android:layout_height='wrap_content'> <TextView android:layout_width='wrap_content' android:layout_height='wrap_content' android:text='請輸入整數x:'/> <EditText android: android:layout_width='wrap_content' android:layout_height='wrap_content' android:layout_marginLeft='20dp' android:ems='20'/> </LinearLayout> <LinearLayout android:layout_width='match_parent' android:layout_height='wrap_content'> <TextView android:layout_width='wrap_content' android:layout_height='wrap_content' android:text='請輸入整數y:'/> <EditText android: android:layout_width='wrap_content' android:layout_height='wrap_content' android:layout_marginLeft='20dp' android:ems='20'/> </LinearLayout> <Button android: android:layout_width='wrap_content' android:layout_height='wrap_content' android:layout_gravity='center' android:text='確認'/> <LinearLayout android:layout_width='match_parent' android:layout_height='wrap_content'> <TextView android:layout_width='wrap_content' android:layout_height='wrap_content' android:text=' x+y=:'/> <TextView android: android:layout_width='wrap_content' android:layout_height='wrap_content' android:layout_marginLeft='20dp' android:textColor='#0aaaaa' android:ems='20'/> </LinearLayout></LinearLayout>

2、下面是MainActivity.java的代碼

package com.example.hjw.calculator;import android.support.v7.app.AppCompatActivity;import android.os.Bundle;import android.view.View;import android.widget.Button;import android.widget.EditText;import android.widget.TextView;public class MainActivity extends AppCompatActivity { private TextView tv1,tv2; private EditText edt1,edt2; private Button btn; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); btn=(Button)this.findViewById(R.id.btn); edt1=(EditText)this.findViewById(R.id.edit1); edt2=(EditText)this.findViewById(R.id.edit2); tv1=(TextView)this.findViewById(R.id.text1); btn.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { String inputText1=edt1.getText().toString(); String inputText2=edt2.getText().toString(); int num1=Integer.valueOf(inputText1).intValue(); int num2=Integer.valueOf(inputText2).intValue(); num1=num1+num2; inputText1=String.valueOf(num1); tv1.setText(inputText1); } }); }}

更多計算器功能實現,請點擊專題: 計算器功能匯總 進行學習

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持好吧啦網。

標簽: Android
相關文章:
主站蜘蛛池模板: 99精品视频免费 | 亚洲欧美日产综合在线看 | 亚洲精品色综合色在线观看 | 欧美激情中文字幕 | 一级网站在线观看 | 久久视频这里只有精品 | 99亚洲精品视频 | 国内精品久久久久久影院老狼 | 亚洲美女视频在线观看 | 日韩性片 | 国产一区二区亚洲精品 | 美美女高清毛片视频黄的一免费 | 国产亚洲精品精品国产亚洲综合 | 18视频免费网站 | 手机看片1024欧美日韩你懂的 | 又黄又免费 | 丁香狠狠色婷婷久久综合 | 午夜爽爽 | vr欧美乱强伦xxxxx | 久久99久久99精品免观看 | 久久女厕一次看个够 | 一级作爱视频免费观看 | 国产国产成人人免费影院 | 一级毛片观看 | 永久免费不卡在线观看黄网站 | 亚洲国语在线视频手机在线 | 亚洲国产成人久久综合一 | 最新更新国内自拍视频 | 亚洲自拍高清 | 九九视频在线观看视频23 | 亚洲国产精品不卡毛片a在线 | 中国国语毛片免费观看视频 | 失禁h啪肉尿出来高h健身房 | 韩国美女爽快一级毛片黄 | 91久久亚洲最新一本 | 亚洲国产一区在线 | a级国产乱理伦片在线观看国 | 亚洲影院手机版777点击进入影院 | 亚洲国产天堂久久精品网 | 色吊丝avav色吊丝 | 毛茸茸年轻成熟亚洲人 |