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

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

Android實現兩個數相加功能

瀏覽:91日期: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
相關文章:
主站蜘蛛池模板: 成 人 a v黄 色| 激情视频一区 | 欧美aaaaa一级毛片在线 | 朝鲜美女免费一级毛片 | 精品国产品国语在线不卡丶 | 国产伦子伦视频免费 | 欧美aaaa在线观看视频免费 | 成人国产三级在线播放 | 久久国产影视免费精品 | 看性过程三级视频在线观看 | 国产性较精品视频免费 | 经典三级久久久久 | 欧美成人全部免费观看1314色 | 一级美国乱色毛片 | aaa一级特黄| 欧美一级大尺度毛片 | 港台三级在线观看 | 成年女人毛片免费播放人 | 97在线免费 | 久爱www免费人成福利播放 | 成人免费看黄网址 | 亚洲精品一区二区久久这里 | 精品国产香蕉伊思人在线 | 免费一级特黄欧美大片久久网 | 波多野结衣在线免费视频 | 色成人亚洲 | 欧美国一级毛片片aa | 久久综合日韩亚洲精品色 | 国产成人精品亚洲一区 | 黄色福利小视频 | 久草综合在线观看 | a级高清观看视频在线看 | 亚洲免费色 | 亚洲伊人色综合网站小说 | 在线视频日韩精品 | 国产成人女人视频在线观看 | 国产成人在线视频 | 国产成人精品免费视频软件 | 欧美日韩精品一区二区三区高清视频 | 国产国产成人精品久久 | 国产精品福利视频萌白酱 |